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
9 changes: 5 additions & 4 deletions driver/config/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ const (
KeyOAuth2GrantJWTIssuedDateOptional = "oauth2.grant.jwt.iat_optional"
KeyOAuth2GrantJWTMaxDuration = "oauth2.grant.jwt.max_ttl"
KeyRefreshTokenHookURL = "oauth2.refresh_token_hook" // #nosec G101
KeyTokenHookURL = "oauth2.token_hook" // #nosec G101
KeyDevelopmentMode = "dev"
)

Expand Down Expand Up @@ -420,11 +421,11 @@ 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) TokenHookURL(ctx context.Context) *url.URL {
return p.getProvider(ctx).RequestURIF(KeyTokenHookURL, nil)
}

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

Expand Down
1 change: 1 addition & 0 deletions driver/registry_base.go
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,7 @@ func (m *RegistryBase) AccessRequestHooks() []oauth2.AccessRequestHook {
if m.arhs == nil {
m.arhs = []oauth2.AccessRequestHook{
oauth2.RefreshTokenHook(m),
oauth2.TokenHook(m),
}
}
return m.arhs
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"session": {
"id_token": {
"id_token_claims": {
"jti": "",
"iss": "http://localhost:4444/",
"sub": "foo",
"aud": [
"app-client"
],
"nonce": "",
"at_hash": "",
"acr": "1",
"amr": null,
"c_hash": "",
"ext": {
"hooked": "legacy"
}
},
"headers": {
"extra": {
}
},
"username": "",
"subject": "foo"
},
"extra": {
"hooked": "legacy"
},
"client_id": "app-client",
"consent_challenge": "",
"exclude_not_before_claim": false,
"allowed_top_level_claims": []
},
"request": {
"client_id": "app-client",
"granted_scopes": [
"offline",
"openid",
"hydra.*"
],
"granted_audience": [],
"grant_types": [
"refresh_token"
],
"payload": {}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"session": {
"id_token": {
"id_token_claims": {
"jti": "",
"iss": "http://localhost:4444/",
"sub": "foo",
"aud": [
"app-client"
],
"nonce": "",
"at_hash": "",
"acr": "1",
"amr": null,
"c_hash": "",
"ext": {
"hooked": "legacy"
}
},
"headers": {
"extra": {
}
},
"username": "",
"subject": "foo"
},
"extra": {
"hooked": "legacy"
},
"client_id": "app-client",
"consent_challenge": "",
"exclude_not_before_claim": false,
"allowed_top_level_claims": []
},
"request": {
"client_id": "app-client",
"granted_scopes": [
"offline",
"openid",
"hydra.*"
],
"granted_audience": [],
"grant_types": [
"refresh_token"
],
"payload": {}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"session": {
"id_token": {
"id_token_claims": {
"jti": "",
"iss": "http://localhost:4444/",
"sub": "foo",
"aud": [
"app-client"
],
"nonce": "",
"at_hash": "",
"acr": "1",
"amr": null,
"c_hash": "",
"ext": {
"hooked": "legacy"
}
},
"headers": {
"extra": {
}
},
"username": "",
"subject": "foo"
},
"extra": {
"hooked": "legacy"
},
"client_id": "app-client",
"consent_challenge": "",
"exclude_not_before_claim": false,
"allowed_top_level_claims": []
},
"request": {
"client_id": "app-client",
"granted_scopes": [
"offline",
"openid",
"hydra.*"
],
"granted_audience": [],
"grant_types": [
"refresh_token"
],
"payload": {}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"session": {
"id_token": {
"id_token_claims": {
"jti": "",
"iss": "http://localhost:4444/",
"sub": "foo",
"aud": [
"app-client"
],
"nonce": "",
"at_hash": "",
"acr": "1",
"amr": null,
"c_hash": "",
"ext": {
"hooked": "legacy"
}
},
"headers": {
"extra": {
}
},
"username": "",
"subject": "foo"
},
"extra": {
"hooked": "legacy"
},
"client_id": "app-client",
"consent_challenge": "",
"exclude_not_before_claim": false,
"allowed_top_level_claims": []
},
"request": {
"client_id": "app-client",
"granted_scopes": [
"offline",
"openid",
"hydra.*"
],
"granted_audience": [],
"grant_types": [
"refresh_token"
],
"payload": {}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"session": {
"id_token": {
"id_token_claims": {
"jti": "",
"iss": "http://localhost:4444/",
"sub": "foo",
"aud": [
"app-client"
],
"nonce": "",
"at_hash": "",
"acr": "1",
"amr": null,
"c_hash": "",
"ext": {
"hooked": "legacy"
}
},
"headers": {
"extra": {
}
},
"username": "",
"subject": "foo"
},
"extra": {
"hooked": "legacy"
},
"client_id": "app-client",
"consent_challenge": "",
"exclude_not_before_claim": false,
"allowed_top_level_claims": []
},
"request": {
"client_id": "app-client",
"granted_scopes": [
"offline",
"openid",
"hydra.*"
],
"granted_audience": [],
"grant_types": [
"refresh_token"
],
"payload": {}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"session": {
"id_token": {
"id_token_claims": {
"jti": "",
"iss": "http://localhost:4444/",
"sub": "foo",
"aud": [
"app-client"
],
"nonce": "",
"at_hash": "",
"acr": "1",
"amr": null,
"c_hash": "",
"ext": {
"hooked": "legacy"
}
},
"headers": {
"extra": {
}
},
"username": "",
"subject": "foo"
},
"extra": {
"hooked": "legacy"
},
"client_id": "app-client",
"consent_challenge": "",
"exclude_not_before_claim": false,
"allowed_top_level_claims": []
},
"request": {
"client_id": "app-client",
"granted_scopes": [
"offline",
"openid",
"hydra.*"
],
"granted_audience": [],
"grant_types": [
"refresh_token"
],
"payload": {}
}
}
Loading