Skip to content

Commit 37bf835

Browse files
Allow adding fields from user info
This change makes it possible to extract extra fields form user info to the generated token. For example, to have `upn` from the Azure token be added to the final JWT, we can add the below to the oauth config section. extract upn from userinfo
1 parent a6e4342 commit 37bf835

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

pkg/idp/oauth/validator.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
jwtlib "github.com/golang-jwt/jwt/v4"
2020
"github.com/greenpau/go-authcrunch/pkg/errors"
2121
"github.com/greenpau/go-authcrunch/pkg/kms"
22+
"go.uber.org/zap"
2223
"strings"
2324
)
2425

@@ -96,8 +97,14 @@ func (b *IdentityProvider) validateAccessToken(state string, data map[string]int
9697
return nil, errors.ErrIdentityProviderOAuthEmailNotFound.WithArgs(b.config.IdentityTokenName)
9798
}
9899
}
99-
100100
m := make(map[string]interface{})
101+
for k, v := range claims {
102+
if _, exists := b.userInfoFields[k]; exists {
103+
b.logger.Debug("Add user info field.", zap.String(k, fmt.Sprintf("%v", v)))
104+
m[k] = v
105+
}
106+
}
107+
101108
for _, k := range tokenFields {
102109
if _, exists := claims[k]; !exists {
103110
continue

0 commit comments

Comments
 (0)