Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add token request hooks for all grant types #3427

Merged
merged 9 commits into from
Mar 26, 2023
21 changes: 16 additions & 5 deletions driver/config/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,10 @@ const (
KeyOAuth2GrantJWTIDOptional = "oauth2.grant.jwt.jti_optional"
KeyOAuth2GrantJWTIssuedDateOptional = "oauth2.grant.jwt.iat_optional"
KeyOAuth2GrantJWTMaxDuration = "oauth2.grant.jwt.max_ttl"
KeyRefreshTokenHookURL = "oauth2.refresh_token_hook" // #nosec G101
KeyRefreshTokenHookURL = "oauth2.refresh_token_hook" // #nosec G101
KeyAuthorizationCodeHookURL = "oauth2.authorization_code_hook" // #nosec G101
KeyClientCredentialsHookURL = "oauth2.client_credentials_hook" // #nosec G101
KeyJWTBearerHookURL = "oauth2.jwt_bearer_hook" // #nosec G101
KeyDevelopmentMode = "dev"
)

Expand Down Expand Up @@ -420,14 +423,22 @@ func (p *DefaultProvider) AccessTokenStrategy(ctx context.Context, additionalSou
return s
}

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

func (p *DefaultProvider) ClientCredentialsHookURL(ctx context.Context) *url.URL {
return p.getProvider(ctx).RequestURIF(KeyClientCredentialsHookURL, nil)
}

func (p *DefaultProvider) TokenRefreshHookURL(ctx context.Context) *url.URL {
return p.getProvider(ctx).RequestURIF(KeyRefreshTokenHookURL, nil)
}

func (p *DefaultProvider) JWTBearerRefreshHookURL(ctx context.Context) *url.URL {
return p.getProvider(ctx).RequestURIF(KeyJWTBearerHookURL, nil)
}

func (p *DefaultProvider) DbIgnoreUnknownTableColumns() bool {
return p.p.Bool(KeyDBIgnoreUnknownTableColumns)
}
Expand Down
3 changes: 3 additions & 0 deletions driver/registry_base.go
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,9 @@ func (m *RegistryBase) AccessRequestHooks() []oauth2.AccessRequestHook {
if m.arhs == nil {
m.arhs = []oauth2.AccessRequestHook{
oauth2.RefreshTokenHook(m),
oauth2.AuthorizationCodeHook(m),
oauth2.ClientCredentialsHook(m),
oauth2.JWTBearerHook(m),
}
}
return m.arhs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,10 @@
"allowed_top_level_claims": []
},
"requester": {
"client_id": "app-client",
"granted_scopes": [
"offline",
"openid",
"hydra.*"
],
"granted_audience": [],
"grant_types": [
"refresh_token"
]
],
"payload": {}
},
"client_id": "app-client",
"granted_scopes": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,10 @@
"allowed_top_level_claims": []
},
"requester": {
"client_id": "app-client",
"granted_scopes": [
"offline",
"openid",
"hydra.*"
],
"granted_audience": [],
"grant_types": [
"refresh_token"
]
],
"payload": {}
},
"client_id": "app-client",
"granted_scopes": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,10 @@
"allowed_top_level_claims": []
},
"requester": {
"client_id": "app-client",
"granted_scopes": [
"offline",
"openid",
"hydra.*"
],
"granted_audience": [],
"grant_types": [
"refresh_token"
]
],
"payload": {}
},
"client_id": "app-client",
"granted_scopes": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,10 @@
"allowed_top_level_claims": []
},
"requester": {
"client_id": "app-client",
sgal marked this conversation as resolved.
Show resolved Hide resolved
"granted_scopes": [
"offline",
"openid",
"hydra.*"
],
"granted_audience": [],
"grant_types": [
"refresh_token"
]
],
"payload": {}
},
"client_id": "app-client",
"granted_scopes": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,10 @@
"allowed_top_level_claims": []
},
"requester": {
"client_id": "app-client",
"granted_scopes": [
"offline",
"openid",
"hydra.*"
],
"granted_audience": [],
"grant_types": [
"refresh_token"
]
],
"payload": {}
},
"client_id": "app-client",
"granted_scopes": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,10 @@
"allowed_top_level_claims": []
},
"requester": {
"client_id": "app-client",
"granted_scopes": [
"offline",
"openid",
"hydra.*"
],
"granted_audience": [],
"grant_types": [
"refresh_token"
]
],
"payload": {}
},
"client_id": "app-client",
"granted_scopes": [
Expand Down
Loading