-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Validate the upstream
email_verified
claim when it makes sense
- Loading branch information
Showing
2 changed files
with
129 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -180,6 +180,93 @@ func TestCallbackEndpoint(t *testing.T) { | |
wantDownstreamPKCEChallengeMethod: downstreamPKCEChallengeMethod, | ||
wantExchangeAndValidateTokensCall: happyExchangeAndValidateTokensArgs, | ||
}, | ||
{ | ||
name: "upstream IDP configures username claim as special claim `email` and `email_verified` upstream claim is missing", | ||
idp: happyUpstream().WithUsernameClaim("email"). | ||
WithIDTokenClaim("email", "[email protected]").Build(), | ||
method: http.MethodGet, | ||
path: newRequestPath().WithState(happyState).String(), | ||
csrfCookie: happyCSRFCookie, | ||
wantStatus: http.StatusFound, | ||
wantRedirectLocationRegexp: happyDownstreamRedirectLocationRegexp, | ||
wantBody: "", | ||
wantDownstreamIDTokenSubject: upstreamIssuer + "?sub=" + upstreamSubject, | ||
wantDownstreamIDTokenUsername: "[email protected]", | ||
wantDownstreamIDTokenGroups: upstreamGroupMembership, | ||
wantDownstreamRequestedScopes: happyDownstreamScopesRequested, | ||
wantDownstreamGrantedScopes: happyDownstreamScopesGranted, | ||
wantDownstreamNonce: downstreamNonce, | ||
wantDownstreamPKCEChallenge: downstreamPKCEChallenge, | ||
wantDownstreamPKCEChallengeMethod: downstreamPKCEChallengeMethod, | ||
wantExchangeAndValidateTokensCall: happyExchangeAndValidateTokensArgs, | ||
}, | ||
{ | ||
name: "upstream IDP configures username claim as special claim `email` and `email_verified` upstream claim is present with true value", | ||
idp: happyUpstream().WithUsernameClaim("email"). | ||
WithIDTokenClaim("email", "[email protected]"). | ||
WithIDTokenClaim("email_verified", true).Build(), | ||
method: http.MethodGet, | ||
path: newRequestPath().WithState(happyState).String(), | ||
csrfCookie: happyCSRFCookie, | ||
wantStatus: http.StatusFound, | ||
wantRedirectLocationRegexp: happyDownstreamRedirectLocationRegexp, | ||
wantBody: "", | ||
wantDownstreamIDTokenSubject: upstreamIssuer + "?sub=" + upstreamSubject, | ||
wantDownstreamIDTokenUsername: "[email protected]", | ||
wantDownstreamIDTokenGroups: upstreamGroupMembership, | ||
wantDownstreamRequestedScopes: happyDownstreamScopesRequested, | ||
wantDownstreamGrantedScopes: happyDownstreamScopesGranted, | ||
wantDownstreamNonce: downstreamNonce, | ||
wantDownstreamPKCEChallenge: downstreamPKCEChallenge, | ||
wantDownstreamPKCEChallengeMethod: downstreamPKCEChallengeMethod, | ||
wantExchangeAndValidateTokensCall: happyExchangeAndValidateTokensArgs, | ||
}, | ||
{ | ||
name: "upstream IDP configures username claim as anything other than special claim `email` and `email_verified` upstream claim is present with false value", | ||
idp: happyUpstream().WithUsernameClaim("some-claim"). | ||
WithIDTokenClaim("some-claim", "joe"). | ||
WithIDTokenClaim("email", "[email protected]"). | ||
WithIDTokenClaim("email_verified", false).Build(), | ||
method: http.MethodGet, | ||
path: newRequestPath().WithState(happyState).String(), | ||
csrfCookie: happyCSRFCookie, | ||
wantStatus: http.StatusFound, // succeed despite `email_verified=false` because we're not using the email claim for anything | ||
wantRedirectLocationRegexp: happyDownstreamRedirectLocationRegexp, | ||
wantBody: "", | ||
wantDownstreamIDTokenSubject: upstreamIssuer + "?sub=" + upstreamSubject, | ||
wantDownstreamIDTokenUsername: "joe", | ||
wantDownstreamIDTokenGroups: upstreamGroupMembership, | ||
wantDownstreamRequestedScopes: happyDownstreamScopesRequested, | ||
wantDownstreamGrantedScopes: happyDownstreamScopesGranted, | ||
wantDownstreamNonce: downstreamNonce, | ||
wantDownstreamPKCEChallenge: downstreamPKCEChallenge, | ||
wantDownstreamPKCEChallengeMethod: downstreamPKCEChallengeMethod, | ||
wantExchangeAndValidateTokensCall: happyExchangeAndValidateTokensArgs, | ||
}, | ||
{ | ||
name: "upstream IDP configures username claim as special claim `email` and `email_verified` upstream claim is present with illegal value", | ||
idp: happyUpstream().WithUsernameClaim("email"). | ||
WithIDTokenClaim("email", "[email protected]"). | ||
WithIDTokenClaim("email_verified", "supposed to be boolean").Build(), | ||
method: http.MethodGet, | ||
path: newRequestPath().WithState(happyState).String(), | ||
csrfCookie: happyCSRFCookie, | ||
wantStatus: http.StatusUnprocessableEntity, | ||
wantBody: "Unprocessable Entity: email_verified claim in upstream ID token has invalid format\n", | ||
wantExchangeAndValidateTokensCall: happyExchangeAndValidateTokensArgs, | ||
}, | ||
{ | ||
name: "upstream IDP configures username claim as special claim `email` and `email_verified` upstream claim is present with false value", | ||
idp: happyUpstream().WithUsernameClaim("email"). | ||
WithIDTokenClaim("email", "[email protected]"). | ||
WithIDTokenClaim("email_verified", false).Build(), | ||
method: http.MethodGet, | ||
path: newRequestPath().WithState(happyState).String(), | ||
csrfCookie: happyCSRFCookie, | ||
wantStatus: http.StatusUnprocessableEntity, | ||
wantBody: "Unprocessable Entity: email_verified claim in upstream ID token has false value\n", | ||
wantExchangeAndValidateTokensCall: happyExchangeAndValidateTokensArgs, | ||
}, | ||
{ | ||
name: "upstream IDP provides username claim configuration as `sub`, so the downstream token subject should be exactly what they asked for", | ||
idp: happyUpstream().WithUsernameClaim("sub").Build(), | ||
|