Skip to content

Conversation

@p3dr0rv
Copy link
Contributor

@p3dr0rv p3dr0rv commented Sep 23, 2025

AB#3385532
https://identitydivision.visualstudio.com/DevEx/_git/AuthLibrariesApiReview/pullrequest/20357

This PR implements passkey registration support for MSAL/Broker/OneAuth on Android WebView through a WebMessageListener bridge. It extends the existing authentication-only passkey functionality to include full registration capabilities, leveraging the standard Android Credential Manager.

🎯 Key Features
Protocol Version Update

  • Current: x-ms-PassKeyAuth: 1.0/passkey (authentication only)
  • New: x-ms-PassKeyAuth: 1.1/passkey (registration + authentication)

Passkey and Credential Manager Integration:

  • Added new CredentialManagerHandler class to encapsulate passkey creation and retrieval using the Android Credential Manager API, including version checks and logging. This simplifies and centralizes interactions with the credential APIs.
  • Introduced PasskeyReplyChannel class to standardize communication of WebAuthn responses (success and error) back to JavaScript via JavaScriptReplyProxy, with detailed error mapping to DOMException types per the WebAuthn specification.

Protocol Version Handling:

  • Updated protocol version validation in FidoChallengeField to accept both 1.0 and 1.1 as supported passkey protocol versions, improving compatibility with newer protocol versions.

Dependency Management:

  • Added androidx.webkit:webkit as a dependency to support enhanced WebView and JavaScript interaction features.

Telemetry will be added in following PR

@p3dr0rv p3dr0rv changed the title Add passkey support with CredentialManager and WebView integration [WIP] Add passkey support with CredentialManager and WebView integration Sep 23, 2025
@github-actions
Copy link

❌ Work item link check failed. Description does not contain AB#{ID}.

Click here to Learn more.

- Set project-level archives name in build.gradle
- Improve PasskeyWebListener to set up WebView message listener
- Refactor WebViewAuthorizationFragment to handle console messages with logging levels
- Update request headers management in WebViewAuthorizationFragment for passkey protocol
- Clean up WebViewMessageListener by removing unused default listener
…oved script handling and logging; add JsScriptRecord for script management; update CommonFlight to disable passkey feature by default.
…rieval logging; streamline credential request handling.
- Added PasskeyReplyChannel for communication between JavaScript and native code.
- Updated CredentialManagerHandler to create and retrieve passkeys.
- Enhanced PasskeyWebListener to handle WebAuthn requests and responses.
- Introduced js-bridge.js for JavaScript integration with WebAuthn.
- Created unit tests for PasskeyReplyChannel to ensure correct message formatting and error handling.
- Removed unnecessary logging statements and improved error handling.
…r handling and message formatting; enhance test coverage for success and error scenarios.
…te Logger class to disable Logcat logging by default; improve logging conditions in Logger.java; ensure proper newline at end of files in CredentialManagerHandler and JsScriptRecord.
…ract Passkey protocol header injection logic into a separate method for improved readability and maintainability.
… with project property for better version management.

Refactor FidoChallengeField to support multiple Passkey protocol versions; improve error handling for unsupported versions.
Clean up CredentialManagerHandler by removing unnecessary exception handling; streamline credential creation and retrieval logic.
Add unit tests for PasskeyWebListener; cover message handling, credential flows, and error scenarios.
Add webkitVersion variable in versions.gradle for centralized version management.
…ent; streamline logic for injecting headers based on flight feature and broker requests.
@p3dr0rv p3dr0rv changed the title [WIP] Add passkey support with CredentialManager and WebView integration Add passkey registration support with CredentialManager and WebView integration Oct 23, 2025
@p3dr0rv p3dr0rv changed the title Add passkey registration support with CredentialManager and WebView integration Add passkey registration support for WebView Oct 23, 2025
@github-actions
Copy link

✅ Work item link check complete. Description contains link AB#3385532 to an Azure Boards work item.

@github-actions github-actions bot changed the title Add passkey registration support for WebView Add passkey registration support for WebView, Fixes AB#3385532 Oct 23, 2025
- Introduced a set of supported passkey protocol versions in FidoConstants.
- Updated throwIfInvalidProtocolVersion method to validate against the new set.
@p3dr0rv p3dr0rv marked this pull request as ready for review October 23, 2025 20:00
@p3dr0rv p3dr0rv requested review from a team as code owners October 23, 2025 20:00
Copilot AI review requested due to automatic review settings October 23, 2025 20:00
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR extends the existing passkey authentication functionality to include passkey registration support in Android WebView through a new WebMessageListener bridge. The implementation leverages the Android Credential Manager API and introduces protocol version 1.1 to differentiate between authentication-only (1.0) and authentication+registration (1.1) capabilities. Key changes include new handler classes for credential operations, JavaScript bridge injection for WebAuthn API interception, and flight-controlled feature rollout.

Key changes:

  • Introduced protocol version 1.1 for passkey registration alongside existing 1.0 authentication
  • Added CredentialManagerHandler, PasskeyWebListener, and PasskeyReplyChannel classes to manage WebAuthn flows
  • Injected JavaScript bridge to intercept navigator.credentials.create/get calls in WebView

Reviewed Changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated no comments.

Show a summary per file
File Description
gradle/versions.gradle Added androidx.webkit dependency version
common4j/src/main/com/microsoft/identity/common/java/flighting/CommonFlight.java Renamed flight from ENABLE_PASSKEY_FEATURE to ENABLE_PASSKEY_REGISTRATION
common4j/src/main/com/microsoft/identity/common/java/constants/FidoConstants.kt Added protocol version 1.1 constants and supported versions set
common/src/test/java/com/microsoft/identity/common/internal/providers/oauth2/PasskeyWebListenerTest.kt Comprehensive unit tests for PasskeyWebListener
common/src/test/java/com/microsoft/identity/common/internal/providers/oauth2/PasskeyReplyChannelTest.kt Unit tests for PasskeyReplyChannel error handling
common/src/main/java/com/microsoft/identity/common/internal/ui/webview/JsScriptRecord.kt New record class for managing injected JavaScript scripts
common/src/main/java/com/microsoft/identity/common/internal/ui/webview/AzureActiveDirectoryWebViewClient.java Added onPageStarted override to inject scripts and script management
common/src/main/java/com/microsoft/identity/common/internal/providers/oauth2/js-bridge.js JavaScript bridge for intercepting WebAuthn API calls
common/src/main/java/com/microsoft/identity/common/internal/providers/oauth2/WebViewAuthorizationFragment.java Integrated PasskeyWebListener setup and protocol header injection
common/src/main/java/com/microsoft/identity/common/internal/providers/oauth2/PasskeyWebListener.kt Core WebMessageListener implementation for WebAuthn flows
common/src/main/java/com/microsoft/identity/common/internal/providers/oauth2/PasskeyReplyChannel.kt Channel for communicating WebAuthn responses to JavaScript
common/src/main/java/com/microsoft/identity/common/internal/providers/oauth2/CredentialManagerHandler.kt Handler for Android Credential Manager API operations
common/src/main/java/com/microsoft/identity/common/internal/fido/FidoChallengeField.kt Updated protocol version validation to support both 1.0 and 1.1
common/build.gradle Added webkit dependency and increased dependency size limit
changelog.txt Added changelog entry for passkey registration feature

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

…Channel, PasskeyWebListener, and WebViewAuthorizationFragment
@p3dr0rv
Copy link
Contributor Author

p3dr0rv commented Oct 23, 2025

Assemble consumers will fail because webkit version is not defined in those libraries yet.

window.PublicKeyCredential = (function () { });
window.PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable =
function () {
return Promise.resolve(false);
Copy link
Contributor

Choose a reason for hiding this comment

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

Just double checking my understanding: this part controls if the passkey option is visible correct? By always returning false here, this ensures that we can control the visibility with webauthn=1 instead?

Copy link
Contributor Author

@p3dr0rv p3dr0rv Oct 24, 2025

Choose a reason for hiding this comment

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

This JS method basically tells the webpage whether the current device has a built-in (platform) authenticator — like a fingerprint sensor, Face ID, or passkey support, so this by default is false in WebView is false, https://developer.mozilla.org/en-US/docs/Web/API/PublicKeyCredential/isUserVerifyingPlatformAuthenticatorAvailable_static.

In our case, since we’re implementing the credential manager integration, we could actually return true. I believe ESTS skips this validation, which is why it worked before, but it makes more sense to explicitly return true here.

I will double check with Suresh

Copy link
Contributor Author

Choose a reason for hiding this comment

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

from Suresh:
image

…ving error handling, and updating WebView authorization logic
@shahzaibj shahzaibj requested a review from Copilot October 29, 2025 16:29
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 15 out of 15 changed files in this pull request and generated 9 comments.

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