1
0
mirror of https://github.com/oauth2-proxy/oauth2-proxy.git synced 2025-11-29 22:48:19 +02:00

Support non-list and complex groups

This commit is contained in:
Nick Meves
2020-11-29 14:58:01 -08:00
parent eb56f24d6d
commit ea5b8cc21f
6 changed files with 166 additions and 36 deletions

View File

@@ -4,6 +4,7 @@ import (
"context"
"errors"
"fmt"
"reflect"
"time"
"github.com/oauth2-proxy/oauth2-proxy/v7/pkg/apis/sessions"
@@ -59,7 +60,7 @@ func (p *OIDCProvider) EnrichSession(ctx context.Context, s *sessions.SessionSta
}
// Try to get missing emails or groups from a profileURL
if s.Email == "" || len(s.Groups) == 0 {
if s.Email == "" || s.Groups == nil {
err := p.callProfileURL(ctx, s)
if err != nil {
logger.Errorf("Warning: Profile URL request failed: %v", err)
@@ -90,16 +91,15 @@ func (p *OIDCProvider) callProfileURL(ctx context.Context, s *sessions.SessionSt
s.Email = email
}
// Handle array & singleton groups cases
if len(s.Groups) == 0 {
groups, err := respJSON.Get(p.GroupsClaim).StringArray()
if err == nil {
s.Groups = groups
} else {
group, err := respJSON.Get(p.GroupsClaim).String()
if err == nil {
s.Groups = []string{group}
for _, group := range coerceArray(respJSON, p.GroupsClaim) {
formatted, err := formatGroup(group)
if err != nil {
logger.Errorf("Warning: unable to format group of type %s with error %s",
reflect.TypeOf(group), err)
continue
}
s.Groups = append(s.Groups, formatted)
}
}