Repository navigation
feat(embedded): add password support to the signup flow - #1139
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
|
| else -> announced ?: transactionState?.passwordRequirement | ||
| } | ||
| val actions = failure.nextActions.map { action -> | ||
| if (action is NextAction.ConfirmSignup) action.withRequired(requirement == CredentialRequirement.REQUIRED) else action |
There was a problem hiding this comment.
Related to the mapper comment: if requirement is REQUIRED but password is null here, withRequired keeps it null and the app can't recover. Maybe build a SignupPassword in that case?
There was a problem hiding this comment.
ConfirmSignup.password is non-null only when the server sends password_complexity_options. withRequired only corrects the required flag on a password that already exists. The server always sends the options when the connection collects a password, so this case shouldn't occur.
| return when ((password as? Map<*, *>)?.get(REQUIRED_KEY) as? Boolean) { | ||
| true -> CredentialRequirement.REQUIRED | ||
| false -> CredentialRequirement.OPTIONAL | ||
| null -> { |
There was a problem hiding this comment.
A password entry without a boolean required still means the connection collects a password. Would OPTIONAL be safer than NONE here? NONE hides the field.
There was a problem hiding this comment.
Password entry is optional. If its present it will have a required property as per the specs. the null is added as a safe check handling
| const val NEXT_SIGNUP_EMAIL_NON_BOOLEAN_REQUIRED = """{ "action": "action:signup:v1", "identifiers": { "email": { "required": "true" }, "phone_number": { "required": false } } }""" | ||
| const val NEXT_SIGNUP_EMAIL_PASSWORD_REQUIRED = """{ "action": "action:signup:v1", "identifiers": { "email": { "required": true } }, "authentication_methods": { "password": { "required": true } } }""" | ||
| const val NEXT_SIGNUP_EMAIL_PASSWORD_OPTIONAL = """{ "action": "action:signup:v1", "identifiers": { "email": { "required": true } }, "authentication_methods": { "password": { "required": false } } }""" | ||
| const val NEXT_SIGNUP_EMAIL_PASSWORD_NO_REQUIRED = """{ "action": "action:signup:v1", "identifiers": { "email": { "required": true } }, "authentication_methods": { "password": {} } }""" |
There was a problem hiding this comment.
Nit: NEXT_SIGNUP_EMAIL_PASSWORD_NO_REQUIRED isn't used anywhere. Use it in a client test or remove it?
| val actions = failure.nextActions.map { action -> | ||
| if (action is NextAction.ConfirmSignup) action.withRequired(requirement == CredentialRequirement.REQUIRED) else action | ||
| } | ||
| transactionState = EmbeddedAuthState(session, requirement) |
There was a problem hiding this comment.
This conflicts with the PKCE PR (#1141): there EmbeddedAuthState is (codeVerifier, authSession?) and the session is rotated with copy(authSession = ...). A fresh EmbeddedAuthState(session, requirement) here would drop the verifier once both land, so whichever merges second should use transactionState?.copy(authSession = session, passwordRequirement = requirement).
There was a problem hiding this comment.
PKCE is a different PR . This conflict is expected and will be resolved when the corresponding PRs will be merged
| */ | ||
| public data object ConfirmSignup : NextAction { | ||
| @ConsistentCopyVisibility | ||
| public data class ConfirmSignup internal constructor( |
There was a problem hiding this comment.
ConfirmSignup was a data object in 5.0.0-beta.3, so this breaks NextAction.ConfirmSignup -> branches and Java's INSTANCE. The new TooManyResendAttempts and Reason values also break exhaustive whens. Please call these out as breaking in the PR description and release notes.
There was a problem hiding this comment.
Yes, Will be called out in the release note. As this is a beta releases breaking changes are expected to occur
| terminalStep(EmbeddedCapability.CONFIRM_SIGNUP) | ||
| @JvmOverloads | ||
| public fun confirmSignup(password: String? = null): Request<Credentials, EmbeddedAuthException> { | ||
| val sentPassword = password?.takeIf { it.isNotEmpty() } |
There was a problem hiding this comment.
The spec caps this password at 2048 characters. A longer one gets a 400, which updateSessionFromFailure treats as terminal and clears the session, so the user has to redo the OTP. Reject it locally without touching the session, or document the limit next to the empty-string rule.
There was a problem hiding this comment.
We don't do any local validation on the SDK. Will update the doc accordingly
| * [EmbeddedAuthError.InsufficientAuthorization.Reason.PASSWORD_NOT_ACCEPTED], and a password the | ||
| * connection's policy rejects with [EmbeddedAuthError.InsufficientAuthorization.Reason.INVALID_PASSWORD]. | ||
| * Each keeps the flow open, so call again with the right input. | ||
| * If the account can't be created, the request completes with the terminal |
There was a problem hiding this comment.
The design lists password_leaked (terminal PasswordLeaked) among the password sign-up errors, but it isn't mentioned here or in signup.md. Worth documenting if the server can return it on confirm.
There was a problem hiding this comment.
PasswordLeaked was added as part of the password signin flow . The password signup changes don't have that error added and hence not added as part of the examples for the same
| public data object TooManyWrongOtpAttempts : EmbeddedAuthError | ||
|
|
||
| /** Terminal: the limit of verification codes sent to this identifier was reached. Restart the flow. */ | ||
| public data object TooManyResendAttempts : EmbeddedAuthError |
There was a problem hiding this comment.
TooManyResendAttempts is missing from the terminal-errors list in examples/embedded-auth/authorize.md and from the error handling in signup.md. Can we add it to both so the examples match the new public case?
There was a problem hiding this comment.
TooManyResendAttempts is not specific to Signup but when a user tries to challenge an identifier multiple times. Will add the doc for the same in the authorize.md file
| override fun onFailure(error: EmbeddedAuthException) { | ||
| onStepFailure(error) | ||
| callback.onFailure(error) | ||
| callback.onFailure(onStepFailure(error)) |
There was a problem hiding this comment.
The corrected required flag only reaches callers through the exception built here, but the client tests only use await(). Please add a start(callback) test so a revert to callback.onFailure(error) can't pass.
There was a problem hiding this comment.
await evnetually calls the callback APIs internally .Didn't add a separate specific suite because of that
| * Terminal step: creates the account and yields credentials, or continues if MFA is required or the | ||
| * password is rejected. Pass the password only when the confirm action offers one. | ||
| */ | ||
| fun confirmSignup(password: String? = null): Unit = runTerminalStep { client.confirmSignup(password).await() } |
There was a problem hiding this comment.
The sample enables BODY logging on DefaultClient (line 35), so this signup password and the token response end up in logcat in plain text. Gate logging on BuildConfig.DEBUG or turn it off.
There was a problem hiding this comment.
This is a sample app change and added intetionally for dev purpose
| private fun NextAction.ConfirmSignup.withRequired(required: Boolean): NextAction.ConfirmSignup = | ||
| NextAction.ConfirmSignup(password?.let { SignupPassword(required, it.complexity) }) | ||
|
|
||
| private fun EmbeddedAuthException.withNextActions( |
There was a problem hiding this comment.
lets have this function as part of EmbeddedAuthException extension
fa9cb7c
Changes
Adds password support to the embedded signup flow, following the server's
/e/authorizeschemas.These are intentional and land in a beta release. They will be called out in the release notes.
NextAction.ConfirmSignupchanges from adata objectto adata classwith apassword: SignupPassword?property. Code that uses the object itself, such asNextAction.ConfirmSignup ->in awhen, and Java'sINSTANCE, no longer compiles.is NextAction.ConfirmSignupstill works.How the flow changes
The
signupaction announces whether the connection collects a password (authentication_methods.password.required). The SDK reports it asSignup.passwordRequirementand keeps it with the session.Once the identifiers are verified, the
signup:confirmaction carriespassword_complexity_options.ConfirmSignup.passwordisnullwhen no password is collected. Otherwise it holdsrequired(carried over from the signup action) and the advisorycomplexity(minimum length and the character types that are all required).confirmSignup(password)sends the password as given, and an empty string counts as none. The SDK does not validate it, and the server decides. A missing required password, a password sent to a connection that collects none, and a rejected password come back as recoverableInsufficientAuthorizationreasons that keep the flow open.access_deniedwithtoo_many_resend_attemptsis now a terminalTooManyResendAttemptserror.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