Repository navigation
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the
|
| ) | ||
| ) | ||
| } | ||
| transactionState = EmbeddedAuthState(codeVerifier = verifier) |
There was a problem hiding this comment.
The verifier is stored here, when the request is built, but the session is added later in updateSessionFromFailure when a response arrives. With two overlapping authorize() calls (a double tap, or one built while another starts) the state can end up as verifier 2 with session 1, and the user only finds out at the token exchange with SessionExpired. Consider capturing the verifier in the authorize request's failure handler and setting EmbeddedAuthState(verifier, session) when the continuation arrives, so the two always arrive together.
| when (error.error) { | ||
| is EmbeddedAuthError.InsufficientAuthorization -> | ||
| error.authSession?.let { transactionState = EmbeddedAuthState(it) } | ||
| error.authSession?.let { session -> transactionState = transactionState?.copy(authSession = session) } |
There was a problem hiding this comment.
transactionState?.copy(...) silently drops the rotated session when the state is already null, for example an old authorize request re-run after the flow ended or after a terminal error. The next step then fails with NoActiveSession; before this change the state was always created here. Setting the full state for the authorize step (see the comment on line 94) would cover this too.
| * Embedded Authorization is currently in [Beta](https://auth0.com/docs/troubleshoot/product-lifecycle/product-release-stages#beta). Please reach out to Auth0 support to get it enabled for your tenant. | ||
| */ | ||
| public class EmbeddedAuthClient(private val auth0: Auth0) { | ||
| public class EmbeddedAuthClient internal constructor( |
There was a problem hiding this comment.
This internal constructor is callable from Java (Kotlin doesn't mangle internal constructors, and AlgorithmHelper is an open class), so an app can inject a fixed verifier and bypass PKCE. Consider a private primary constructor with an internal factory for tests.
| /** | ||
| * The state of the flow in progress, created by `authorize()` with the PKCE [codeVerifier] that is sent with | ||
| * the token exchange. [authSession] is the latest session from the server, and is `null` until the first | ||
| * response arrives. Neither is ever logged. |
There was a problem hiding this comment.
"Neither is ever logged" doesn't hold with DefaultClient.enableLogging(true): it logs request bodies at BODY level without redaction, so code_verifier appears in the /oauth/token request. Either redact it in the logging interceptor or reword to say the SDK itself doesn't log it.
|
|
||
| // ── PKCE ───────────────────────────────────────────────────────────────────── | ||
|
|
||
| @Test |
There was a problem hiding this comment.
Please pin the exact key sets of the Initiate and /oauth/token bodies, since the Initiate schema rejects unknown fields and the exchange must not send redirect_uri. Also worth adding: no code_challenge or code_verifier in the identify, challenge and verifyOtp bodies, invalid_grant at the exchange giving SessionExpired, and the overlapping authorize case.
Changes
Adds PKCE to every embedded
/e/authorizeflow. The server acceptscode_challengeandcode_challenge_methodon the first/e/authorizecall, binds the authorization code to the challenge, and then requires the matchingcode_verifierat/oauth/token. Clients that enforce PKCE, and public clients on tenants with the PKCE-required setting, are rejected without it, so the SDK now always sends it.How it works
authorize()creates a new code verifier for each flow, sends itscode_challengewithcode_challenge_method: "S256", and creates the flow state with the verifier.auth_sessionin that state, so the verifier is kept for the whole flow.code_verifierwith the token exchange. This matters because the state is cleared as soon as the server issues the code, before the exchange runs.authorize()fails locally without sending a request. It never falls back to a flow without PKCE.Classes and methods
AlgorithmHelpermoves fromprovider/AlgorithmHelper.javatoutil/AlgorithmHelper.ktas aninternal open class, so the web-auth and embedded flows share one implementation. Behavior is unchanged.PKCE.javaand its tests only change their import.EmbeddedAuthStatenow holdscodeVerifierand a nullableauthSession. ItstoStringhides both.EmbeddedAuthClientgains aninternalconstructor that takes anAlgorithmHelper, used by tests. The publicEmbeddedAuthClient(auth0)constructor is unchanged.examples/embedded-auth/authorize.mdhas a short note that PKCE is added automatically.Testing
This change adds unit test coverage
This change adds integration test coverage
This change has been tested on the latest version of the platform/language or why not
Checklist
I have read the Auth0 general contribution guidelines
I have read the Auth0 Code of Conduct
All existing and new tests complete without errors