@@ -35,10 +35,10 @@ import (
3535
3636// MakeAccessToken implements the oidc.AccessTokenProvider interface.
3737func (p * Provider ) MakeAccessToken (ctx context.Context , audience string , auth identity.AuthRecord ) (string , error ) {
38- return p .makeAccessToken (ctx , audience , auth , nil )
38+ return p .makeAccessToken (ctx , audience , auth , nil , nil )
3939}
4040
41- func (p * Provider ) makeAccessToken (ctx context.Context , audience string , auth identity.AuthRecord , signingMethod jwt.SigningMethod ) (string , error ) {
41+ func (p * Provider ) makeAccessToken (ctx context.Context , audience string , auth identity.AuthRecord , signingMethod jwt.SigningMethod , refreshTokenClaims * konnect. RefreshTokenClaims ) (string , error ) {
4242 sk , ok := p .getSigningKey (signingMethod )
4343 if ! ok {
4444 return "" , fmt .Errorf ("no signing key" )
@@ -67,6 +67,17 @@ func (p *Provider) makeAccessToken(ctx context.Context, audience string, auth id
6767 accessTokenClaims .IdentityClaims = userWithClaims .Claims ()
6868 }
6969 accessTokenClaims .IdentityProvider = auth .Manager ().Name ()
70+ if accessTokenClaims .IdentityClaims != nil && refreshTokenClaims != nil && refreshTokenClaims .IdentityClaims != nil {
71+ if refreshTokenClaims .IdentityProvider != accessTokenClaims .IdentityProvider {
72+ return "" , fmt .Errorf ("refresh token claims provider mismatch" )
73+ }
74+ for k , v := range refreshTokenClaims .IdentityClaims {
75+ // Force to use refresh token identity claim values. This also locks all
76+ // the extra claims for id and access tokens to the ones provided from
77+ // the refresh token claims (which currently includes the session id).
78+ accessTokenClaims .IdentityClaims [k ] = v
79+ }
80+ }
7081 }
7182
7283 // Support additional custom user specific claims.
@@ -113,7 +124,7 @@ func (p *Provider) makeAccessToken(ctx context.Context, audience string, auth id
113124 return accessToken .SignedString (sk .PrivateKey )
114125}
115126
116- func (p * Provider ) makeIDToken (ctx context.Context , ar * payload.AuthenticationRequest , auth identity.AuthRecord , session * payload.Session , accessTokenString string , codeString string , signingMethod jwt.SigningMethod ) (string , error ) {
127+ func (p * Provider ) makeIDToken (ctx context.Context , ar * payload.AuthenticationRequest , auth identity.AuthRecord , session * payload.Session , accessTokenString string , codeString string , signingMethod jwt.SigningMethod , refreshTokenClaims * konnect. RefreshTokenClaims ) (string , error ) {
117128 sk , ok := p .getSigningKey (signingMethod )
118129 if ! ok {
119130 return "" , fmt .Errorf ("no signing key" )
@@ -160,6 +171,18 @@ func (p *Provider) makeIDToken(ctx context.Context, ar *payload.AuthenticationRe
160171 if userWithClaims , ok := user .(identity.UserWithClaims ); ok {
161172 accessTokenClaims .IdentityClaims = userWithClaims .Claims ()
162173 }
174+ accessTokenClaims .IdentityProvider = auth .Manager ().Name ()
175+ if accessTokenClaims .IdentityClaims != nil && refreshTokenClaims != nil && refreshTokenClaims .IdentityClaims != nil {
176+ if refreshTokenClaims .IdentityProvider != accessTokenClaims .IdentityProvider {
177+ return "" , fmt .Errorf ("refresh token claims provider mismatch" )
178+ }
179+ for k , v := range refreshTokenClaims .IdentityClaims {
180+ // Force to use refresh token identity claim values. This also locks all
181+ // the extra claims for id and access tokens to the ones provided from
182+ // the refresh token claims (which currently includes the session id).
183+ accessTokenClaims .IdentityClaims [k ] = v
184+ }
185+ }
163186
164187 if withIDTokenClaimsRequest {
165188 // Apply additional information from ID token claims request.
0 commit comments