Skip to content

OIDC Nonce and OAuth State Support#337

Open
luizgustavo09 wants to merge 3 commits into
uber:developfrom
luizgustavo09:luizgustavo09/develop/add-nonce-param
Open

OIDC Nonce and OAuth State Support#337
luizgustavo09 wants to merge 3 commits into
uber:developfrom
luizgustavo09:luizgustavo09/develop/add-nonce-param

Conversation

@luizgustavo09

Copy link
Copy Markdown
Contributor

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 /authorize and validated after token exchange against the nonce claim in the returned id_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 /authorize and validated on the callback before the authorization code is extracted.

Test plan

Manual

  1. Run the example app with openid profile scopes and shouldExchangeAuthCode: true
  2. Complete the login flow
  3. Verify client.nonce is non-nil in the completion handler
  4. Confirm no .nonceMismatch or .stateMismatch errors

References

@luizgustavo09 luizgustavo09 force-pushed the luizgustavo09/develop/add-nonce-param branch from 97a126f to 19133e8 Compare June 4, 2026 02:09
@luizgustavo09 luizgustavo09 changed the title Add nonce and state to authorize request OIDC Nonce & OAuth State Support Jun 4, 2026
@luizgustavo09 luizgustavo09 changed the title OIDC Nonce & OAuth State Support OIDC Nonce and OAuth State Support Jun 4, 2026
Comment thread Sources/UberAuth/Authorize/AuthorizationCodeAuthProvider.swift Outdated
scopes: [String] = AuthorizationCodeAuthProvider.defaultScopes,
shouldExchangeAuthCode: Bool = false,
prompt: Prompt? = nil,
nonce: String? = nil,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A provider would solve this right? As long as it generates a unique nonce every time

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make it here

We're gonna use the nonce provided on the init of AuthorizationCodeAuthProvider only once

Comment thread Sources/UberAuth/Authorize/AuthorizationCodeAuthProvider.swift
Comment thread Sources/UberAuth/PAR/ParRequest.swift
Comment thread Sources/UberAuth/Client.swift
Comment thread Sources/UberAuth/Authorize/AuthorizationCodeAuthProvider.swift Outdated
@luizgustavo09 luizgustavo09 force-pushed the luizgustavo09/develop/add-nonce-param branch from 19133e8 to d07523e Compare June 4, 2026 18:45
@luizgustavo09 luizgustavo09 force-pushed the luizgustavo09/develop/add-nonce-param branch from d07523e to 78a5619 Compare June 4, 2026 18:56
Comment thread Sources/UberAuth/Authorize/AuthorizationCodeAuthProvider.swift Outdated

@mohssenfathi mohssenfathi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you can, in a later PR can you update the example app with these changes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants