Skip to content

Commit

Permalink
chore: resolve comments
Browse files Browse the repository at this point in the history
  • Loading branch information
wood-push-melon committed Mar 12, 2024
1 parent 15d0e22 commit f930a81
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 24 deletions.
12 changes: 6 additions & 6 deletions handler/oauth2/flow_authorize_code_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type AuthorizeCodeHandler struct {
AuthorizeCodeStrategy AuthorizeCodeStrategy
}

func (c AuthorizeCodeHandler) Code(ctx context.Context, requester fosite.AccessRequester) (code string, signature string, err error) {
func (c AuthorizeCodeHandler) Code(ctx context.Context, requester fosite.AccessRequester) (code string, signature string, _ error) {
code = requester.GetRequestForm().Get("code")
signature = c.AuthorizeCodeStrategy.AuthorizeCodeSignature(ctx, code)
return code, signature, nil
Expand All @@ -35,13 +35,13 @@ func (s AuthorizeExplicitGrantSessionHandler) Session(ctx context.Context, reque
req, err := s.AuthorizeCodeStorage.GetAuthorizeCodeSession(ctx, codeSignature, requester.GetSession())

if err != nil && errors.Is(err, fosite.ErrInvalidatedAuthorizeCode) {
if req == nil {
return req, fosite.ErrServerError.
WithHint("Misconfigured code lead to an error that prohibited the OAuth 2.0 Framework from processing this request.").
WithDebug("\"GetAuthorizeCodeSession\" must return a value for \"fosite.Requester\" when returning \"ErrInvalidatedAuthorizeCode\".")
if req != nil {
return req, err
}

return req, err
return req, fosite.ErrServerError.
WithHint("Misconfigured code lead to an error that prohibited the OAuth 2.0 Framework from processing this request.").
WithDebug("\"GetAuthorizeCodeSession\" must return a value for \"fosite.Requester\" when returning \"ErrInvalidatedAuthorizeCode\".")
}

if err != nil && errors.Is(err, fosite.ErrNotFound) {
Expand Down
30 changes: 17 additions & 13 deletions handler/oauth2/flow_generic_code_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,14 @@ func (c *GenericCodeTokenEndpointHandler) PopulateTokenEndpointResponse(ctx cont
return errorsx.WithStack(fosite.ErrUnknownRequest)
}

code, signature, err := c.Code(ctx, requester)
if err != nil {
var code, signature string
var err error
if code, signature, err = c.Code(ctx, requester); err != nil {
return err
}

ar, err := c.Session(ctx, requester, signature)
if err != nil {
var ar fosite.Requester
if ar, err = c.Session(ctx, requester, signature); err != nil {
return errorsx.WithStack(fosite.ErrServerError.WithWrap(err).WithDebug(err.Error()))
}

Expand All @@ -97,7 +98,8 @@ func (c *GenericCodeTokenEndpointHandler) PopulateTokenEndpointResponse(ctx cont
requester.GrantAudience(audience)
}

accessToken, accessTokenSignature, err := c.AccessTokenStrategy.GenerateAccessToken(ctx, requester)
var accessToken, accessTokenSignature string
accessToken, accessTokenSignature, err = c.AccessTokenStrategy.GenerateAccessToken(ctx, requester)
if err != nil {
return errorsx.WithStack(fosite.ErrServerError.WithWrap(err).WithDebug(err.Error()))
}
Expand Down Expand Up @@ -157,20 +159,22 @@ func (c *GenericCodeTokenEndpointHandler) HandleTokenEndpointRequest(ctx context
return errorsx.WithStack(errorsx.WithStack(fosite.ErrUnknownRequest))
}

if err := c.ValidateGrantTypes(requester); err != nil {
var err error
if err = c.ValidateGrantTypes(requester); err != nil {
return err
}

code, signature, err := c.Code(ctx, requester)
if err != nil {
var code, signature string
if code, signature, err = c.Code(ctx, requester); err != nil {
return err
}

ar, err := c.Session(ctx, requester, signature)
if ar != nil && err != nil && (errors.Is(err, fosite.ErrInvalidatedAuthorizeCode) || errors.Is(err, fosite.ErrInvalidatedDeviceCode)) {
return c.revokeTokens(ctx, requester.GetID())
}
if err != nil {
var ar fosite.Requester
if ar, err = c.Session(ctx, requester, signature); err != nil {
if ar != nil && (errors.Is(err, fosite.ErrInvalidatedAuthorizeCode) || errors.Is(err, fosite.ErrInvalidatedDeviceCode)) {
return c.revokeTokens(ctx, requester.GetID())
}

return err
}

Expand Down
10 changes: 5 additions & 5 deletions handler/rfc8628/token_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ func (s DeviceSessionHandler) Session(ctx context.Context, requester fosite.Acce
req, err := s.DeviceCodeStorage.GetDeviceCodeSession(ctx, codeSignature, requester.GetSession())

if err != nil && errors.Is(err, fosite.ErrInvalidatedDeviceCode) {
if req == nil {
return req, fosite.ErrServerError.
WithHint("Misconfigured code lead to an error that prohibited the OAuth 2.0 Framework from processing this request.").
WithDebug("\"GetDeviceCodeSession\" must return a value for \"fosite.Requester\" when returning \"ErrInvalidatedDeviceCode\".")
if req != nil {
return req, err
}

return req, nil
return req, fosite.ErrServerError.
WithHint("Misconfigured code lead to an error that prohibited the OAuth 2.0 Framework from processing this request.").
WithDebug("\"GetDeviceCodeSession\" must return a value for \"fosite.Requester\" when returning \"ErrInvalidatedDeviceCode\".")
}

if err != nil && errors.Is(err, fosite.ErrNotFound) {
Expand Down

0 comments on commit f930a81

Please sign in to comment.