OIDC Nonce and OAuth State Support#337
Conversation
97a126f to
19133e8
Compare
| scopes: [String] = AuthorizationCodeAuthProvider.defaultScopes, | ||
| shouldExchangeAuthCode: Bool = false, | ||
| prompt: Prompt? = nil, | ||
| nonce: String? = nil, |
There was a problem hiding this comment.
I'm guessing the reason we don't immediately store this in pendingNonce and instead do nonce > clientNonce > pendingNonce is that the client can use AuthorizationCodeAuthProvider multiple times?
Do we instead need to pass in some "nonceProvider"? What happens if we execute multiple auth requests with the same nonce provided by the caller?
There was a problem hiding this comment.
is that the client can use AuthorizationCodeAuthProvider multiple times?
Yes!
Do we instead need to pass in some "nonceProvider"?
Let me add it, much better than have this nonce > clientNonce > pendingNonce within the class
What happens if we execute multiple auth requests with the same nonce provided by the caller?
Hmm the SDK doesn't handle this, if the client don't pass the nonce is fine because the at every call we create a new one, but if the client pass nonce in AuthorizationCodeAuthProvider and execute multiple calls we are gonna reuse the param.
Do you have any suggestion to handle this?
There was a problem hiding this comment.
A provider would solve this right? As long as it generates a unique nonce every time
There was a problem hiding this comment.
Make it here
We're gonna use the nonce provided on the init of AuthorizationCodeAuthProvider only once
19133e8 to
d07523e
Compare
d07523e to
78a5619
Compare
mohssenfathi
left a comment
There was a problem hiding this comment.
If you can, in a later PR can you update the example app with these changes
Summary
This PR adds two complementary security mechanisms to the authorization flow: an OIDC nonce for replay attack prevention and an OAuth state parameter for CSRF protection at the callback level.
Nonce
A random nonce is now generated on every authorization request. It is sent in
/authorizeand validated after token exchange against thenonceclaim in the returnedid_token.Client can supply their own nonce via
AuthorizationCodeAuthProvider(nonce:), If no nonce is provided, the SDK generates one automatically.Validation follows OIDC Core §3.1.3.7.
State
A random state is always generated internally and is not exposed to callers. It is sent in
/authorizeand validated on the callback before the authorization code is extracted.Test plan
Manual
openid profilescopes andshouldExchangeAuthCode: trueclient.nonceis non-nil in the completion handler.nonceMismatchor.stateMismatcherrorsReferences