Skip to content

Commit

Permalink
fix: address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
sgal committed Mar 23, 2023
1 parent 4d5fb14 commit fb5bd4b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 29 deletions.
16 changes: 0 additions & 16 deletions driver/config/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -424,34 +424,18 @@ func (p *DefaultProvider) AccessTokenStrategy(ctx context.Context, additionalSou
}

func (p *DefaultProvider) AuthorizationCodeHookURL(ctx context.Context) *url.URL {
if len(p.getProvider(ctx).String(KeyAuthorizationCodeHookURL)) == 0 {
return nil
}

return p.getProvider(ctx).RequestURIF(KeyAuthorizationCodeHookURL, nil)
}

func (p *DefaultProvider) ClientCredentialsHookURL(ctx context.Context) *url.URL {
if len(p.getProvider(ctx).String(KeyClientCredentialsHookURL)) == 0 {
return nil
}

return p.getProvider(ctx).RequestURIF(KeyClientCredentialsHookURL, nil)
}

func (p *DefaultProvider) TokenRefreshHookURL(ctx context.Context) *url.URL {
if len(p.getProvider(ctx).String(KeyRefreshTokenHookURL)) == 0 {
return nil
}

return p.getProvider(ctx).RequestURIF(KeyRefreshTokenHookURL, nil)
}

func (p *DefaultProvider) JWTBearerRefreshHookURL(ctx context.Context) *url.URL {
if len(p.getProvider(ctx).String(KeyJWTBearerHookURL)) == 0 {
return nil
}

return p.getProvider(ctx).RequestURIF(KeyJWTBearerHookURL, nil)
}

Expand Down
26 changes: 13 additions & 13 deletions oauth2/hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ func JWTBearerHook(reg interface {
}
}

func callHook(ctx context.Context, reg x.HTTPClientProvider, requester fosite.AccessRequester, hookType string, hookURL *url.URL) error {
if !requester.GetGrantTypes().ExactOne(hookType) {
func callHook(ctx context.Context, reg x.HTTPClientProvider, requester fosite.AccessRequester, grantType string, hookURL *url.URL) error {
if !requester.GetGrantTypes().ExactOne(grantType) {
return nil
}

Expand All @@ -138,7 +138,7 @@ func callHook(ctx context.Context, reg x.HTTPClientProvider, requester fosite.Ac

payload := map[string][]string{}

if requester.GetGrantTypes().ExactOne("urn:ietf:params:oauth:grant-type:jwt-bearer") || requester.GetGrantTypes().ExactOne("client_credentials") {
if grantType == "urn:ietf:params:oauth:grant-type:jwt-bearer" || grantType == "client_credentials" {
payload = requester.GetRequestForm()
}

Expand All @@ -163,8 +163,8 @@ func callHook(ctx context.Context, reg x.HTTPClientProvider, requester fosite.Ac
return errorsx.WithStack(
fosite.ErrServerError.
WithWrap(err).
WithDescription(fmt.Sprintf("An error occurred while encoding the %s hook.", hookType)).
WithDebugf("Unable to encode the %v hook body: %s", hookType, err),
WithDescription(fmt.Sprintf("An error occurred while encoding the %s hook.", grantType)).
WithDebugf("Unable to encode the %v hook body: %s", grantType, err),
)
}

Expand All @@ -173,7 +173,7 @@ func callHook(ctx context.Context, reg x.HTTPClientProvider, requester fosite.Ac
return errorsx.WithStack(
fosite.ErrServerError.
WithWrap(err).
WithDescription(fmt.Sprintf("An error occurred while preparing the %s hook.", hookType)).
WithDescription(fmt.Sprintf("An error occurred while preparing the %s hook.", grantType)).
WithDebugf("Unable to prepare the HTTP Request: %s", err),
)
}
Expand All @@ -184,7 +184,7 @@ func callHook(ctx context.Context, reg x.HTTPClientProvider, requester fosite.Ac
return errorsx.WithStack(
fosite.ErrServerError.
WithWrap(err).
WithDescription(fmt.Sprintf("An error occurred while executing the %s hook.", hookType)).
WithDescription(fmt.Sprintf("An error occurred while executing the %s hook.", grantType)).
WithDebugf("Unable to execute HTTP Request: %s", err),
)
}
Expand All @@ -199,14 +199,14 @@ func callHook(ctx context.Context, reg x.HTTPClientProvider, requester fosite.Ac
case http.StatusForbidden:
return errorsx.WithStack(
fosite.ErrAccessDenied.
WithDescription(fmt.Sprintf("The %s hook target responded with an error.", hookType)).
WithDebugf(fmt.Sprintf("%s hook responded with HTTP status code: %s", hookType, resp.Status)),
WithDescription(fmt.Sprintf("The %s hook target responded with an error.", grantType)).
WithDebugf(fmt.Sprintf("%s hook responded with HTTP status code: %s", grantType, resp.Status)),
)
default:
return errorsx.WithStack(
fosite.ErrServerError.
WithDescription(fmt.Sprintf("The %s hook target responded with an error.", hookType)).
WithDebugf(fmt.Sprintf("%s hook responded with HTTP status code: %s", hookType, resp.Status)),
WithDescription(fmt.Sprintf("The %s hook target responded with an error.", grantType)).
WithDebugf(fmt.Sprintf("%s hook responded with HTTP status code: %s", grantType, resp.Status)),
)
}

Expand All @@ -215,8 +215,8 @@ func callHook(ctx context.Context, reg x.HTTPClientProvider, requester fosite.Ac
return errorsx.WithStack(
fosite.ErrServerError.
WithWrap(err).
WithDescription(fmt.Sprintf("The %s hook target responded with an error.", hookType)).
WithDebugf(fmt.Sprintf("Response from %s hook could not be decoded: %s", hookType, err)),
WithDescription(fmt.Sprintf("The %s hook target responded with an error.", grantType)).
WithDebugf(fmt.Sprintf("Response from %s hook could not be decoded: %s", grantType, err)),
)
}

Expand Down

0 comments on commit fb5bd4b

Please sign in to comment.