Skip to content

Commit

Permalink
feat: add token request hooks for all grant types (ory#3427)
Browse files Browse the repository at this point in the history
Added a generic token hook that is called for all grant types and includes `payload` with a single allowed value - `assertion` to cover the `jwt-bearer` grant type customization.

The existing `refresh token hook` is left unchanged and is considered to be deprecated in favor of the new hook logic. The `refresh token hook` will at some point be removed.

Closes ory#3244
Closes ory/fosite#729
  • Loading branch information
sgal authored and harnash committed Apr 12, 2023
1 parent eae78c9 commit 5865a8f
Show file tree
Hide file tree
Showing 20 changed files with 1,284 additions and 231 deletions.
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 @@ -513,6 +513,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

0 comments on commit 5865a8f

Please sign in to comment.