@@ -49,7 +49,7 @@ func (p *OIDCProvider) Redeem(ctx context.Context, redirectURL, code string) (*s
49 return p.createSession(ctx, token, false)
49 return p.createSession(ctx, token, false)
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
53// such as User, Email, Groups with provider specific API calls.
53// such as User, Email, Groups with provider specific API calls.
54func (p *OIDCProvider) EnrichSession(ctx context.Context, s *sessions.SessionState) error {
54func (p *OIDCProvider) EnrichSession(ctx context.Context, s *sessions.SessionState) error {
55 if p.ProfileURL.String() == "" {
55 if p.ProfileURL.String() == "" {
@@ -61,7 +61,7 @@ func (p *OIDCProvider) EnrichSession(ctx context.Context, s *sessions.SessionSta
62 // Try to get missing emails or groups from a profileURL
62 // Try to get missing emails or groups from a profileURL
63 if s.Email == "" || s.Groups == nil {
63 if s.Email == "" || s.Groups == nil {
64− err := p.callProfileURL(ctx, s)
64+ err := p.enrichFromProfileURL(ctx, s)
65 if err != nil {
65 if err != nil {
66 logger.Errorf("Warning: Profile URL request failed: %v", err)
66 logger.Errorf("Warning: Profile URL request failed: %v", err)
@@ -74,9 +74,9 @@ func (p *OIDCProvider) EnrichSession(ctx context.Context, s *sessions.SessionSta
74 return nil
74 return nil
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
78// an OIDC profile URL
78// 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 {
80 respJSON, err := requests.New(p.ProfileURL.String()).
80 respJSON, err := requests.New(p.ProfileURL.String()).
81 WithContext(ctx).
81 WithContext(ctx).
82 WithHeaders(makeOIDCHeader(s.AccessToken)).
82 WithHeaders(makeOIDCHeader(s.AccessToken)).
@@ -91,22 +91,23 @@ func (p *OIDCProvider) callProfileURL(ctx context.Context, s *sessions.SessionSt
91 s.Email = email
91 s.Email = email
94− if len(s.Groups) == 0 {
94+ if len(s.Groups) > 0 {
95− for _, group := range coerceArray(respJSON, p.GroupsClaim) {
97+ for _, group := range coerceArray(respJSON, p.GroupsClaim) {
96− formatted, err := formatGroup(group)
98+ formatted, err := formatGroup(group)
97− if err != nil {
99+ if err != nil {
98− logger.Errorf("Warning: unable to format group of type %s with error %s",
100+ logger.Errorf("Warning: unable to format group of type %s with error %s",
99− reflect.TypeOf(group), err)
101+ reflect.TypeOf(group), err)
100− continue
102+ continue
102− s.Groups = append(s.Groups, formatted)
104+ s.Groups = append(s.Groups, formatted)
106 return nil
107 return nil
109−// ValidateSessionState checks that the session's IDToken is still valid
110+// ValidateSession checks that the session's IDToken is still valid
110func (p *OIDCProvider) ValidateSession(ctx context.Context, s *sessions.SessionState) bool {
111func (p *OIDCProvider) ValidateSession(ctx context.Context, s *sessions.SessionState) bool {
111 _, err := p.Verifier.Verify(ctx, s.IDToken)
112 _, err := p.Verifier.Verify(ctx, s.IDToken)
112 return err == nil
113 return err == nil