fix: use idToken for mapping when using old configs (#5458)

* fix: use idToken for mapping when using old configs

* fix events and add tests
This commit is contained in:
Livio Spring
2023-03-16 16:47:22 +01:00
committed by GitHub
parent a8a2edadc2
commit 1896f13952
24 changed files with 1371 additions and 331 deletions

View File

@@ -20,6 +20,7 @@ type Provider struct {
isCreationAllowed bool
isAutoCreation bool
isAutoUpdate bool
useIDToken bool
userInfoMapper func(info oidc.UserInfo) idp.User
authOptions []rp.AuthURLOpt
}
@@ -55,6 +56,13 @@ func WithAutoUpdate() ProviderOpts {
}
}
// WithIDTokenMapping enables that information to map the user is retrieved from the id_token and not the userinfo endpoint.
func WithIDTokenMapping() ProviderOpts {
return func(p *Provider) {
p.useIDToken = true
}
}
// WithRelyingPartyOption allows to set an additional [rp.Option] like [rp.WithPKCE].
func WithRelyingPartyOption(option rp.Option) ProviderOpts {
return func(p *Provider) {

View File

@@ -47,6 +47,9 @@ func (s *Session) FetchUser(ctx context.Context) (user idp.User, err error) {
if err != nil {
return nil, err
}
if s.Provider.useIDToken {
info = s.Tokens.IDTokenClaims
}
u := s.Provider.userInfoMapper(info)
return u, nil
}