feat(auth): Add /token endpoint to request a access token
This commit is contained in:
@@ -29,7 +29,7 @@ func TokenController(c *fiber.Ctx) error {
|
||||
return utils.NewHTTPResponse(fiber.StatusBadRequest, &fiber.Map{"error": err.Error()}, "", nil, nil).Send(c)
|
||||
}
|
||||
|
||||
masterlog.Debug("Token request validated", map[string]interface{}{"path": c.Path()})
|
||||
masterlog.Debug("Token request validated", map[string]interface{}{"path": c.Path(), "body": request})
|
||||
|
||||
response := services.Token(request.ClientID, request.GrantType, request.Code, request.RedirectURI, request.ClientSecret)
|
||||
masterlog.Debug("Token response sent", map[string]interface{}{"path": c.Path()})
|
||||
|
||||
@@ -14,10 +14,12 @@ import (
|
||||
|
||||
func AuthMiddleware() fiber.Handler {
|
||||
return func(c *fiber.Ctx) error {
|
||||
if slices.Contains(config.CONFIG.UnprotectedEndpoints, c.Path()) {
|
||||
tokenEndpoint := "/token"
|
||||
if slices.Contains(config.CONFIG.UnprotectedEndpoints, c.Path()) || c.Path() == tokenEndpoint {
|
||||
masterlog.Debug("Unprotected endpoint", map[string]interface{}{"path": c.Path()})
|
||||
return c.Next()
|
||||
}
|
||||
|
||||
authHeader := c.Get("Authorization")
|
||||
if authHeader == "" {
|
||||
masterlog.Debug("No token provided", map[string]interface{}{"path": c.Path(), "authorization": c.Get("Authorization")})
|
||||
|
||||
@@ -45,6 +45,10 @@ func Authorize(userID, clientID, redirectURI, responseType, scope, state string)
|
||||
authorizationCodeString := fmt.Sprintf("%s:%s", authorizationID.String(), authorizationCode)
|
||||
authorizationCodeBase64 := base64.StdEncoding.EncodeToString([]byte(authorizationCodeString))
|
||||
|
||||
masterlog.Debug("Authorization created successfully", map[string]interface{}{"authorization_id": authorizationID.String(), "authorization_code": authorizationCode, "client_id": clientID})
|
||||
masterlog.Debug("Authorization code base64", map[string]interface{}{"authorization_code_base64": authorizationCodeBase64})
|
||||
masterlog.Debug("State", map[string]interface{}{"state": state})
|
||||
|
||||
response := AuthorizeResponse{
|
||||
Code: authorizationCodeBase64,
|
||||
State: state,
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
package services
|
||||
|
||||
Reference in New Issue
Block a user