Skip to content

Commit

Permalink
Allow adding fields from user info
Browse files Browse the repository at this point in the history
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
  • Loading branch information
MartinWallgren committed Apr 19, 2023
1 parent a6e4342 commit 37bf835
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion pkg/idp/oauth/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
jwtlib "github.com/golang-jwt/jwt/v4"
"github.com/greenpau/go-authcrunch/pkg/errors"
"github.com/greenpau/go-authcrunch/pkg/kms"
"go.uber.org/zap"
"strings"
)

Expand Down Expand Up @@ -96,8 +97,14 @@ func (b *IdentityProvider) validateAccessToken(state string, data map[string]int
return nil, errors.ErrIdentityProviderOAuthEmailNotFound.WithArgs(b.config.IdentityTokenName)
}
}

m := make(map[string]interface{})
for k, v := range claims {
if _, exists := b.userInfoFields[k]; exists {
b.logger.Debug("Add user info field.", zap.String(k, fmt.Sprintf("%v", v)))
m[k] = v
}
}

for _, k := range tokenFields {
if _, exists := claims[k]; !exists {
continue
Expand Down

0 comments on commit 37bf835

Please sign in to comment.