Skip to content

feat(embedded): add password support to the signup flow - #1139

Open
pmathew92 wants to merge 2 commits into
v5_developmentfrom
feat/embedded_signup_password
Open

pmathew92 wants to merge 2 commits into
v5_developmentfrom
feat/embedded_signup_password

Conversation

@pmathew92

@pmathew92 pmathew92 commented Nov 13, 2026 •

Copy link
Copy Markdown
Member

Changes

Adds password support to the embedded signup flow, following the server's /e/authorize schemas.

How the flow changes

  • The signup action announces whether the connection collects a password (authentication_methods.password.required). The SDK reports it as Signup.passwordRequirement and keeps it with the session.

  • Once the identifiers are verified, the signup:confirm action carries password_complexity_options. ConfirmSignup.password is null when no password is collected. Otherwise it holds required (carried over from the signup action) and the advisory complexity (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 recoverable InsufficientAuthorization reasons that keep the flow open.

  • access_denied with too_many_resend_attempts is now a terminal TooManyResendAttempts error.

  • 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

@coderabbitai

coderabbitai Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Team
  • Run ID: 54a8c34b-31fa-42bb-90ed-42ed5dec9c47

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@pmathew92
pmathew92 marked this pull request as ready for review November 13, 2026 05:08
@pmathew92
pmathew92 requested a review from a team as a code owner November 13, 2026 05:08
@pmathew92 pmathew92 changed the title feat(embedded): add password support to the signup flow [non-main] feat(embedded): add password support to the signup flow Nov 13, 2026
val minLength = (options[MIN_LENGTH_KEY] as? Number)?.toWholeInt()?.takeIf { it >= 1 }
if (minLength == null) {
Log.w(TAG, "Ignoring signup password: required field \"$MIN_LENGTH_KEY\" was missing or invalid.")
return null

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 min_length is missing or bad, we drop the whole password object. On a connection that requires a password, the app then shows no field and the server keeps returning password_required with the same ConfirmSignup(null), so the user can't finish. Can we fall back to a default complexity (e.g. minLength = 1, no types) when the connection collects a password, instead of returning null?

else -> announced ?: transactionState?.passwordRequirement
}
val actions = failure.nextActions.map { action ->
if (action is NextAction.ConfirmSignup) action.withRequired(requirement == CredentialRequirement.REQUIRED) else action

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.

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?

return when ((password as? Map<*, *>)?.get(REQUIRED_KEY) as? Boolean) {
true -> CredentialRequirement.REQUIRED
false -> CredentialRequirement.OPTIONAL
null -> {

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 password entry without a boolean required still means the connection collects a password. Would OPTIONAL be safer than NONE here? NONE hides the field.

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": {} } }"""

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.

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)

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.

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).

*/
public data object ConfirmSignup : NextAction {
@ConsistentCopyVisibility
public data class ConfirmSignup internal constructor(

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.

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.

terminalStep(EmbeddedCapability.CONFIRM_SIGNUP)
@JvmOverloads
public fun confirmSignup(password: String? = null): Request<Credentials, EmbeddedAuthException> {
val sentPassword = password?.takeIf { it.isNotEmpty() }

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.

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.

* [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

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.

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.

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

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.

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?

override fun onFailure(error: EmbeddedAuthException) {
onStepFailure(error)
callback.onFailure(error)
callback.onFailure(onStepFailure(error))

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.

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.

* 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() }

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.

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.

@NandanPrabhu
NandanPrabhu self-requested a review November 17, 2026 10:53

This branch has not been deployed

No deployments
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.

3 participants