feat(auth): Add /token endpoint to request a access token
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"git.secnex.io/secnex/masterlog"
|
||||
"git.secnex.io/secnex/oauth2-api/models"
|
||||
"git.secnex.io/secnex/oauth2-api/repositories"
|
||||
"git.secnex.io/secnex/oauth2-api/utils"
|
||||
@@ -19,11 +20,13 @@ type AuthorizeResponse struct {
|
||||
}
|
||||
|
||||
func Authorize(userID, clientID, redirectURI, responseType, scope, state string) *utils.HTTPResponse {
|
||||
application, err := repositories.GetApplicationByClientID(clientID)
|
||||
application, err := repositories.GetApplicationByID(clientID)
|
||||
if err != nil {
|
||||
masterlog.Debug("Application not found", map[string]interface{}{"error": err.Error(), "client_id": clientID})
|
||||
return utils.NewHTTPResponse(http.StatusUnauthorized, &fiber.Map{"error": "Application not found"}, "", nil, nil)
|
||||
}
|
||||
if application.ExpiresAt.Before(time.Now().UTC()) {
|
||||
masterlog.Debug("Application expired", map[string]interface{}{"client_id": clientID})
|
||||
return utils.NewHTTPResponse(http.StatusUnauthorized, &fiber.Map{"error": "Application expired"}, "", nil, nil)
|
||||
}
|
||||
authorizationID := uuid.New()
|
||||
@@ -35,6 +38,7 @@ func Authorize(userID, clientID, redirectURI, responseType, scope, state string)
|
||||
UserID: uuid.MustParse(userID),
|
||||
}
|
||||
if err := repositories.CreateAuthorization(authorization); err != nil {
|
||||
masterlog.Debug("Failed to create authorization", map[string]interface{}{"error": err.Error(), "client_id": clientID})
|
||||
return utils.NewHTTPResponse(http.StatusInternalServerError, &fiber.Map{"error": "Failed to create authorization"}, "", nil, nil)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user