Skip to content

Commit

Permalink
move setting of oauth2metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
DrDaveD committed Jul 24, 2020
1 parent f57d734 commit 3f8d02e
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions path_oidc.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,6 @@ func (b *jwtAuthBackend) pathCallback(ctx context.Context, req *logical.Request,

var rawToken string
var oauth2Token *oauth2.Token
oauth2Metadata := make(map[string]string)

code := d.Get("code").(string)
if code == noCode {
Expand All @@ -240,14 +239,6 @@ func (b *jwtAuthBackend) pathCallback(ctx context.Context, req *logical.Request,
if !ok {
return logical.ErrorResponse(errTokenVerification + " No id_token found in response."), nil
}

for _, mdname := range role.Oauth2Metadata {
md, ok := oauth2Token.Extra(mdname).(string)
if !ok {
return logical.ErrorResponse(errTokenVerification + " No " + mdname + " found in response."), nil
}
oauth2Metadata[mdname] = md
}
}

if role.VerboseOIDCLogging {
Expand All @@ -265,6 +256,8 @@ func (b *jwtAuthBackend) pathCallback(ctx context.Context, req *logical.Request,
}
delete(allClaims, "nonce")

oauth2Metadata := make(map[string]string)

// If we have a token, attempt to fetch information from the /userinfo endpoint
// and merge it with the existing claims data. A failure to fetch additional information
// from this endpoint will not invalidate the authorization flow.
Expand All @@ -278,6 +271,15 @@ func (b *jwtAuthBackend) pathCallback(ctx context.Context, req *logical.Request,
}
logFunc("error reading /userinfo endpoint", "error", err)
}

// Also fetch any requested extra oauth2 metadata
for _, mdname := range role.Oauth2Metadata {
md, ok := oauth2Token.Extra(mdname).(string)
if !ok {
return logical.ErrorResponse(errTokenVerification + " No " + mdname + " found in response."), nil
}
oauth2Metadata[mdname] = md
}
}

if role.VerboseOIDCLogging {
Expand Down

0 comments on commit 3f8d02e

Please sign in to comment.