Skip to content

feat: Add password enrollment to MyAccount API#1003

Open
pmathew92 wants to merge 5 commits into
mainfrom
myaccount_password
Open

feat: Add password enrollment to MyAccount API#1003
pmathew92 wants to merge 5 commits into
mainfrom
myaccount_password

Conversation

@pmathew92

@pmathew92 pmathew92 commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Adds password authentication-method enrollment to MyAccountAPIClient via a two-step flow:
    • enrollPassword()POST /me/v1/authentication-methods (type=password), returns a new PasswordEnrollmentChallenge (id, auth_session, policy).
    • verifyPassword(authenticationId, authSession, newPassword)POST /me/v1/authentication-methods/{id}/verify, returns a PasswordAuthenticationMethod.
  • Introduces a typed PasswordPolicy model (complexity, profile-data, history, dictionary) so apps can build a compliant password UI.
  • Adds unit tests (MyAccountAPIClientTest, MyAccountAPIMockServer) covering payloads, deserialization, and DPoP.
  • Documents the flow in EXAMPLES.md.

Summary by CodeRabbit

  • New Features

    • Added a two-step password enrollment flow to My Account, including request and verification steps.
    • Included password policy details in enrollment challenge responses (complexity, profile data, history, dictionary rules).
  • Documentation

    • Updated the examples guide with a new “Enroll a Password Method” walkthrough and Kotlin/Java samples.
  • Bug Fixes

    • Improved enrollment challenge parsing to detect and correctly deserialize password-specific challenges.
  • Tests

    • Added coverage for password enrollment/verification requests, response parsing, and DPoP-enabled requests.

@coderabbitai

coderabbitai Bot commented Jul 6, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 9d4ad9d9-11d5-490f-8cfb-9198d6e3c81f

📥 Commits

Reviewing files that changed from the base of the PR and between 594ff78 and f6dce7a.

📒 Files selected for processing (3)
  • EXAMPLES.md
  • auth0/src/main/java/com/auth0/android/myaccount/MyAccountAPIClient.kt
  • auth0/src/test/java/com/auth0/android/myaccount/MyAccountAPIClientTest.kt
🚧 Files skipped from review as they are similar to previous changes (3)
  • auth0/src/main/java/com/auth0/android/myaccount/MyAccountAPIClient.kt
  • EXAMPLES.md
  • auth0/src/test/java/com/auth0/android/myaccount/MyAccountAPIClientTest.kt

📝 Walkthrough

Walkthrough

This PR adds password enrollment and verification support to MyAccountAPIClient, introduces password policy and enrollment challenge models, updates tests and mock responses, and documents the new two-step flow in EXAMPLES.md.

Changes

Password Enrollment Feature

Layer / File(s) Summary
Password data models and deserialization
auth0/src/main/java/com/auth0/android/result/PasswordPolicy.kt, auth0/src/main/java/com/auth0/android/result/EnrollmentChallenge.kt
Adds PasswordPolicy and nested data classes, adds PasswordEnrollmentChallenge, and updates EnrollmentChallenge.Deserializer to map "policy" JSON to the new challenge type.
MyAccountAPIClient enrollPassword and verifyPassword methods
auth0/src/main/java/com/auth0/android/myaccount/MyAccountAPIClient.kt
Adds public enrollPassword and verifyPassword methods for the authentication-methods endpoints, updates imports, and introduces NEW_PASSWORD_KEY.
Tests and mock server support for password flows
auth0/src/test/java/com/auth0/android/myaccount/MyAccountAPIClientTest.kt, auth0/src/test/java/com/auth0/android/util/MyAccountAPIMockServer.kt
Adds password mock helpers and tests covering request payloads, response parsing, and DPoP header handling.
Documentation for password enrollment
EXAMPLES.md
Adds a TOC entry and a new “Enroll a Password Method” section with Kotlin and Java examples for the two-step flow.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant App
  participant MyAccountAPIClient
  participant Auth0API

  App->>MyAccountAPIClient: enrollPassword(userIdentity, connection)
  MyAccountAPIClient->>Auth0API: POST /authentication-methods (type=password)
  Auth0API-->>MyAccountAPIClient: PasswordEnrollmentChallenge (id, authSession, policy)
  MyAccountAPIClient-->>App: PasswordEnrollmentChallenge

  App->>MyAccountAPIClient: verifyPassword(authenticationMethodId, authSession, newPassword)
  MyAccountAPIClient->>Auth0API: POST /authentication-methods/{id}/verify
  Auth0API-->>MyAccountAPIClient: PasswordAuthenticationMethod
  MyAccountAPIClient-->>App: PasswordAuthenticationMethod
Loading

Suggested reviewers: subhankarmaiti

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: adding password enrollment support to the MyAccount API.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch myaccount_password

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@pmathew92 pmathew92 marked this pull request as ready for review July 6, 2026 06:13
@pmathew92 pmathew92 requested a review from a team as a code owner July 6, 2026 06:13

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Nitpick comments (1)
auth0/src/main/java/com/auth0/android/myaccount/MyAccountAPIClient.kt (1)

776-793: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Duplicates buildEnrollmentRequest's URL/POST construction.

enrollPassword reconstructs the same URL-building and factory.post(...).addParameters(...).addHeader(...) pattern used by buildEnrollmentRequest (Line 898), only differing in the response adapter type. Consider parameterizing buildEnrollmentRequest (or adding an overload) to accept the target class/adapter so this and passkeyEnrollmentChallenge-style methods share one code path.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@auth0/src/main/java/com/auth0/android/myaccount/MyAccountAPIClient.kt` around
lines 776 - 793, The enrollPassword method is duplicating the same URL
construction and POST request setup already handled by buildEnrollmentRequest,
with only the response adapter type differing. Refactor buildEnrollmentRequest
in MyAccountAPIClient to accept the target response class or adapter so it can
build the shared request path and headers once, then update enrollPassword to
call that shared helper instead of rebuilding the request inline. Use the
existing buildEnrollmentRequest and enrollPassword symbols to keep this and
similar methods like passkeyEnrollmentChallenge on a single code path.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@auth0/src/main/java/com/auth0/android/myaccount/MyAccountAPIClient.kt`:
- Around line 795-821: The KDoc usage example for
MyAccountAPIClient.verifyPassword shows the arguments in the wrong order, which
does not match the method signature. Update the example to pass
authenticationMethodId, authSession, and then newPassword in the same order used
by verifyPassword and the test call so the documentation reflects the public API
accurately.

In `@auth0/src/test/java/com/auth0/android/myaccount/MyAccountAPIClientTest.kt`:
- Around line 616-627: The `verifyPassword` test is calling
`client.verifyPassword(...)` with `authSession` and `newPassword` swapped, which
makes the intent misleading. Update the argument order in
`MyAccountAPIClientTest` to match the `verifyPassword(authenticationMethodId,
authSession, newPassword)` signature, using `AUTH_SESSION` for the auth session
slot and `"S3cr3tP@ssw0rd"` for the new password slot. Keep the existing
assertions and request flow intact.

In `@EXAMPLES.md`:
- Around line 2636-2658: The `verifyPassword` examples in `EXAMPLES.md` use the
wrong argument order and should be updated to match the new flow. In both the
Kotlin and Java snippets, swap the session token and new password values in the
`myAccountClient.verifyPassword(...)` call so the auth session comes before the
new password, keeping the rest of the callback examples unchanged.

---

Nitpick comments:
In `@auth0/src/main/java/com/auth0/android/myaccount/MyAccountAPIClient.kt`:
- Around line 776-793: The enrollPassword method is duplicating the same URL
construction and POST request setup already handled by buildEnrollmentRequest,
with only the response adapter type differing. Refactor buildEnrollmentRequest
in MyAccountAPIClient to accept the target response class or adapter so it can
build the shared request path and headers once, then update enrollPassword to
call that shared helper instead of rebuilding the request inline. Use the
existing buildEnrollmentRequest and enrollPassword symbols to keep this and
similar methods like passkeyEnrollmentChallenge on a single code path.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: db18f62d-d690-4234-9c6f-0aad0cfa9072

📥 Commits

Reviewing files that changed from the base of the PR and between aa6581c and 594ff78.

📒 Files selected for processing (6)
  • EXAMPLES.md
  • auth0/src/main/java/com/auth0/android/myaccount/MyAccountAPIClient.kt
  • auth0/src/main/java/com/auth0/android/result/EnrollmentChallenge.kt
  • auth0/src/main/java/com/auth0/android/result/PasswordPolicy.kt
  • auth0/src/test/java/com/auth0/android/myaccount/MyAccountAPIClientTest.kt
  • auth0/src/test/java/com/auth0/android/util/MyAccountAPIMockServer.kt

Comment thread EXAMPLES.md
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