@@ -49,7 +49,7 @@ func (p *OIDCProvider) Redeem(ctx context.Context, redirectURL, code string) (*s
4949 return p.createSession(ctx, token, false)
5050}
5151
52−// EnrichSessionState is called after Redeem to allow providers to enrich session fields
52+// EnrichSession is called after Redeem to allow providers to enrich session fields
5353// such as User, Email, Groups with provider specific API calls.
5454func (p *OIDCProvider) EnrichSession(ctx context.Context, s *sessions.SessionState) error {
5555 if p.ProfileURL.String() == "" {
@@ -61,7 +61,7 @@ func (p *OIDCProvider) EnrichSession(ctx context.Context, s *sessions.SessionSta
6161
6262 // Try to get missing emails or groups from a profileURL
6363 if s.Email == "" || s.Groups == nil {
64− err := p.callProfileURL(ctx, s)
64+ err := p.enrichFromProfileURL(ctx, s)
6565 if err != nil {
6666 logger.Errorf("Warning: Profile URL request failed: %v", err)
6767 }
@@ -74,9 +74,9 @@ func (p *OIDCProvider) EnrichSession(ctx context.Context, s *sessions.SessionSta
7474 return nil
7575}
7676
77−// callProfileURL enriches a session's Email & Groups via the JSON response of
77+// enrichFromProfileURL enriches a session's Email & Groups via the JSON response of
7878// an OIDC profile URL
79−func (p *OIDCProvider) callProfileURL(ctx context.Context, s *sessions.SessionState) error {
79+func (p *OIDCProvider) enrichFromProfileURL(ctx context.Context, s *sessions.SessionState) error {
8080 respJSON, err := requests.New(p.ProfileURL.String()).
8181 WithContext(ctx).
8282 WithHeaders(makeOIDCHeader(s.AccessToken)).
@@ -91,22 +91,23 @@ func (p *OIDCProvider) callProfileURL(ctx context.Context, s *sessions.SessionSt
9191 s.Email = email
9292 }
9393
94− if len(s.Groups) == 0 {
95− for _, group := range coerceArray(respJSON, p.GroupsClaim) {
96− formatted, err := formatGroup(group)
97− if err != nil {
98− logger.Errorf("Warning: unable to format group of type %s with error %s",
99− reflect.TypeOf(group), err)
100− continue
101− }
102− s.Groups = append(s.Groups, formatted)
94+ if len(s.Groups) > 0 {
95+ return nil
96+ }
97+ for _, group := range coerceArray(respJSON, p.GroupsClaim) {
98+ formatted, err := formatGroup(group)
99+ if err != nil {
100+ logger.Errorf("Warning: unable to format group of type %s with error %s",
101+ reflect.TypeOf(group), err)
102+ continue
103103 }
104+ s.Groups = append(s.Groups, formatted)
104105 }
105106
106107 return nil
107108}
108109
109−// ValidateSessionState checks that the session's IDToken is still valid
110+// ValidateSession checks that the session's IDToken is still valid
110111func (p *OIDCProvider) ValidateSession(ctx context.Context, s *sessions.SessionState) bool {
111112 _, err := p.Verifier.Verify(ctx, s.IDToken)
112113 return err == nil