Skip to content
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
2f6fc36
Add passkey support with CredentialManager and WebView integration
p3dr0rv Sep 22, 2025
a43bfef
debug
p3dr0rv Sep 23, 2025
a02b892
Log success response in PasskeyWebListener and update JavaScript mess…
p3dr0rv Sep 24, 2025
963d700
Merge branch 'dev' into pedroro/passkey-reg-prototype
p3dr0rv Sep 24, 2025
7e2e2f3
Merge branch 'dev' into pedroro/passkey-reg-prototype
p3dr0rv Oct 7, 2025
be90629
Enhance WebView message handling and update Gradle configurations
p3dr0rv Oct 8, 2025
ef52c35
Refactor Passkey protocol handling and enhance WebView integration
p3dr0rv Oct 10, 2025
150aea2
Add passkey registration flight control and update WebView header han…
p3dr0rv Oct 10, 2025
89e0f50
Refactor PasskeyWebListener and WebViewAuthorizationFragment for impr…
p3dr0rv Oct 10, 2025
a6ec873
Refactor CredentialManagerHandler to improve passkey creation and ret…
p3dr0rv Oct 10, 2025
83b9c49
Refactor imports in CredentialManagerHandler for improved clarity and…
p3dr0rv Oct 11, 2025
578242c
Implement Passkey functionality with WebAuthn support
p3dr0rv Oct 16, 2025
5c8bdbb
Refactor PasskeyReplyChannel and related components for improved erro…
p3dr0rv Oct 17, 2025
036fd39
Refactor build.gradle to set project archivesBaseName correctly; upda…
p3dr0rv Oct 17, 2025
8304ba5
Add WebView support for Passkey functionality; update dependencies an…
p3dr0rv Oct 17, 2025
8b31fd0
Update minified JavaScript code in PasskeyWebListener; add detailed i…
p3dr0rv Oct 18, 2025
6f5e568
Merge branch 'dev' into pedroro/passkey-reg-prototype
p3dr0rv Oct 21, 2025
1fc5328
Refactor request header handling in WebViewAuthorizationFragment; ext…
p3dr0rv Oct 21, 2025
89f6544
Update dependencies in build.gradle; replace hardcoded webkit version…
p3dr0rv Oct 21, 2025
f172ccb
Remove passkey feature flight toggle; set passkey registration to dis…
p3dr0rv Oct 23, 2025
d87a5cc
Enhance Passkey protocol header handling in WebViewAuthorizationFragm…
p3dr0rv Oct 23, 2025
0c0cbfc
Merge branch 'dev' into pedroro/passkey-reg-prototype
p3dr0rv Oct 23, 2025
f206ee5
Refactor createPasskey and getPasskey methods in CredentialManagerHan…
p3dr0rv Oct 23, 2025
2fb63ad
Merge branch 'pedroro/passkey-reg-prototype' of https://github.com/Az…
p3dr0rv Oct 23, 2025
7117010
Add passkey registration support for WebView in changelog
p3dr0rv Oct 23, 2025
8e13fde
Update default dependencies size to 16 MB in build.gradle
p3dr0rv Oct 23, 2025
6c20ed8
Add support for dynamic passkey protocol version validation
p3dr0rv Oct 23, 2025
8bbf3d4
Refactor code for improved readability and formatting in PasskeyReply…
p3dr0rv Oct 23, 2025
d611ac0
Enhance passkey functionality by adding span context retrieval, impro…
p3dr0rv Oct 24, 2025
49c9101
Refactor WebViewAuthorizationFragment for improved code clarity and m…
p3dr0rv Oct 28, 2025
2b1088d
Update common/src/main/java/com/microsoft/identity/common/internal/pr…
p3dr0rv Oct 29, 2025
7c0d8ec
Update common/src/main/java/com/microsoft/identity/common/internal/fi…
p3dr0rv Oct 29, 2025
be46370
Update common/src/main/java/com/microsoft/identity/common/internal/pr…
p3dr0rv Oct 29, 2025
999011b
update WebViewAuthorizationFragment logging methods for improved privacy
p3dr0rv Oct 29, 2025
12a2d84
Add WebAuthn JavaScript bridge and enhance PasskeyWebListener for deb…
p3dr0rv Nov 1, 2025
d4c5cf3
Update common/src/main/assets/js-bridge.js
p3dr0rv Nov 3, 2025
2bf51b7
Update WebAuthn interface name and modify user verification promise r…
p3dr0rv Nov 3, 2025
eda9cca
Merge branch 'dev' into pedroro/passkey-reg-prototype
p3dr0rv Nov 4, 2025
78a51db
Enhance JsScriptRecord to validate sovereign cloud URLs and require '…
p3dr0rv Nov 5, 2025
475e918
Add JsScriptRecord validation for sovereign cloud URLs and implement …
p3dr0rv Nov 6, 2025
43408f5
Merge branch 'dev' into pedroro/passkey-reg-prototype
p3dr0rv Nov 6, 2025
914cfee
Clarify comment in JsScriptRecord.isAllowedForUrl to specify checking…
p3dr0rv Nov 6, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
vNext
----------
- [MINOR] Add passkey registration support for WebView (#2769)
- [MAJOR] Add KeyStoreBackedSecretKeyProvider (#2674)
- [MINOR] Add Open Id configuration issuer validation reporting in OpenIdProviderConfigurationClient (#2751)
- [MINOR] Add helper method to record elapsed time (#2768)
Expand Down
3 changes: 2 additions & 1 deletion common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ android {
}

dependencies {
implementation "androidx.webkit:webkit:$rootProject.ext.webkitVersion"
testImplementation project(path: ':testutils')

localApi(project(":common4j")) {
Expand Down Expand Up @@ -409,7 +410,7 @@ tasks.withType(GenerateMavenPom).all {
}
}

def dependenciesSizeInMb = project.hasProperty("dependenciesSizeMb") ? project.dependenciesSizeMb : "15"
def dependenciesSizeInMb = project.hasProperty("dependenciesSizeMb") ? project.dependenciesSizeMb : "16"
String configToCheck = project.hasProperty("dependenciesSizeCheckConfig") ? project.dependenciesSizeCheckConfig : "distReleaseRuntimeClasspath"
tasks.register("dependenciesSizeCheck") {
doLast() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,10 @@ data class FidoChallengeField<K>(private val field: FidoRequestField,
@Throws(ClientException::class)
fun throwIfInvalidProtocolVersion(field: FidoRequestField, value: String?): String {
val version = throwIfInvalidRequiredParameter(field, value)
if (version != FidoConstants.PASSKEY_PROTOCOL_VERSION) {
throw ClientException(ClientException.PASSKEY_PROTOCOL_REQUEST_PARSING_ERROR, "Provided protocol version is not currently supported.")
if (FidoConstants.supportedPasskeyProtocolVersions.contains(version)) {
return version
}
return version
throw ClientException(ClientException.PASSKEY_PROTOCOL_REQUEST_PARSING_ERROR, "Provided protocol version is not currently supported.")
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// Copyright (c) Microsoft Corporation.
// All rights reserved.
//
// This code is licensed under the MIT License.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files(the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions :
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
package com.microsoft.identity.common.internal.providers.oauth2

import android.app.Activity
import android.os.Build
import androidx.credentials.CreatePublicKeyCredentialRequest
import androidx.credentials.CreatePublicKeyCredentialResponse
import androidx.credentials.CredentialManager
import androidx.credentials.GetCredentialRequest
import androidx.credentials.GetCredentialResponse
import androidx.credentials.GetPublicKeyCredentialOption
import com.microsoft.identity.common.logging.Logger

class CredentialManagerHandler(private val activity: Activity) {

companion object {
const val TAG = "CredentialManagerHandler"
}

private val mCredMan = CredentialManager.create(activity.applicationContext)

/**
* Encapsulates the create passkey API for credential manager in a less error-prone manner.
*
* @param request a create public key credential request JSON required by [CreatePublicKeyCredentialRequest].
* @return [CreatePublicKeyCredentialResponse] containing the result of the credential creation.
*/
suspend fun createPasskey(request: String): CreatePublicKeyCredentialResponse {
val methodTag = "$TAG:createPasskey"
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
val createRequest = CreatePublicKeyCredentialRequest(request)
return (mCredMan.createCredential(
activity,
createRequest
) as CreatePublicKeyCredentialResponse).also {
Logger.info(methodTag, "Passkey created successfully.")
}
} else {
Logger.warn(
methodTag,
"Passkey creation is not supported on Android versions below 9 (Pie). Current version: ${Build.VERSION.SDK_INT}"
)
throw UnsupportedOperationException("Passkey creation requires Android 9 or higher.")
}
}

/**
* Encapsulates the get passkey API for credential manager in a less error-prone manner.
*
* @param request a get public key credential request JSON required by [GetCredentialRequest].
* @return [GetCredentialResponse] containing the result of the credential retrieval.
*/
suspend fun getPasskey(request: String): GetCredentialResponse {
val methodTag = "$TAG:getPasskey"
val getRequest = GetCredentialRequest(listOf(GetPublicKeyCredentialOption(request)))
return mCredMan.getCredential(activity, getRequest).also {
Logger.info(methodTag, "Passkey retrieved successfully.")
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,229 @@
// Copyright (c) Microsoft Corporation.
// All rights reserved.
//
// This code is licensed under the MIT License.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files(the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions :
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
package com.microsoft.identity.common.internal.providers.oauth2

import android.annotation.SuppressLint
import androidx.credentials.exceptions.CreateCredentialCancellationException
import androidx.credentials.exceptions.CreateCredentialInterruptedException
import androidx.credentials.exceptions.CreateCredentialProviderConfigurationException
import androidx.credentials.exceptions.CreateCredentialUnknownException
import androidx.credentials.exceptions.GetCredentialCancellationException
import androidx.credentials.exceptions.GetCredentialInterruptedException
import androidx.credentials.exceptions.GetCredentialProviderConfigurationException
import androidx.credentials.exceptions.GetCredentialUnknownException
import androidx.credentials.exceptions.NoCredentialException
import androidx.webkit.JavaScriptReplyProxy
import com.microsoft.identity.common.logging.Logger
import org.json.JSONObject
import kotlin.jvm.Throws


/**
* Communication channel for sending WebAuthn responses back to JavaScript via [JavaScriptReplyProxy].
*
* Formats messages as JSON containing status, data, and request type for WebAuthn credential operations.
*
* @property replyProxy Proxy for sending messages to JavaScript.
* @property requestType Type of WebAuthn request (e.g., "create", "get"). Defaults to "unknown".
*/
class PasskeyReplyChannel(
private val replyProxy: JavaScriptReplyProxy,
private val requestType: String = "unknown"
) {
companion object {
const val TAG = "PasskeyReplyChannel"

// JSON message structure keys
const val STATUS_KEY = "status"
const val DATA_KEY = "data"
const val TYPE_KEY = "type"

// DOMException error details keys
const val DOM_EXCEPTION_MESSAGE_KEY = "domExceptionMessage"
const val DOM_EXCEPTION_NAME_KEY = "domExceptionName"

// Message status values
const val SUCCESS_STATUS = "success"
const val ERROR_STATUS = "error"

// DOMException names per W3C WebAuthn specification
const val DOM_EXCEPTION_NOT_ALLOWED_ERROR = "NotAllowedError"
const val DOM_EXCEPTION_ABORT_ERROR = "AbortError"
const val DOM_EXCEPTION_NOT_SUPPORTED_ERROR = "NotSupportedError"
const val DOM_EXCEPTION_UNKNOWN_ERROR = "UnknownError"

}

/**
* Sealed class representing messages sent to JavaScript.
*/
sealed class ReplyMessage {
abstract val type: String
abstract val status: String
abstract val data: JSONObject

/**
* Success message containing credential data.
*
* @property json JSON string with credential response data.
* @property type Request type that succeeded.
*/
class Success(val json: String, override val type: String) : ReplyMessage() {
override val status = SUCCESS_STATUS
override val data: JSONObject =
runCatching { JSONObject(json) }.getOrElse { JSONObject() }
}

/**
* Error message with DOMException details.
*
* @property domExceptionMessage Error description.
* @property domExceptionName DOMException name per W3C spec.
* @property type Request type that failed.
*/
class Error(
private val domExceptionMessage: String,
private val domExceptionName: String = DOM_EXCEPTION_NOT_ALLOWED_ERROR,
override val type: String
) : ReplyMessage() {
override val status = ERROR_STATUS
override val data: JSONObject
get() {
return JSONObject().apply {
put(DOM_EXCEPTION_MESSAGE_KEY, domExceptionMessage)
put(DOM_EXCEPTION_NAME_KEY, domExceptionName)
}
}
}

/** Serializes the message to JSON string. */
override fun toString(): String {
return JSONObject().apply {
put(STATUS_KEY, status)
put(DATA_KEY, data)
put(TYPE_KEY, type)
}.toString()
}
}

/**
* Posts a success message with credential data.
*
* @param json JSON string containing the credential response.
*/
fun postSuccess(json: String) {
val methodTag = "$TAG:postSuccess"
send(ReplyMessage.Success(json, requestType))
Logger.info(methodTag, "RequestType: $requestType, was successful.")
}

/**
* Posts an error message with a custom error description.
*
* @param errorMessage Error description to send.
*/
fun postError(errorMessage: String) {
postErrorInternal(
ReplyMessage.Error(domExceptionMessage = errorMessage, type = requestType)
)
}

/**
* Posts an error message based on a thrown exception.
*
* Maps credential exceptions to appropriate DOMException types.
*
* @param throwable Exception to convert and send.
*/
fun postError(throwable: Throwable) {
postErrorInternal(throwableToErrorMessage(throwable))
}

/**
* Internal method to send error messages and log them.
*/
private fun postErrorInternal(errorMessage: ReplyMessage.Error) {
val methodTag = "$TAG:postError"
send(errorMessage)
Logger.error(methodTag, "RequestType: $requestType, failed with error: $errorMessage", null)
}

/**
* Maps credential exceptions to DOMException error messages.
*
* Conversion table:
* - Cancellation/No credential → NotAllowedError
* - Interruption → AbortError
* - Configuration → NotSupportedError
* - Unknown → UnknownError
*
* @param throwable Exception to map.
* @return Error message with appropriate DOMException details.
*/
private fun throwableToErrorMessage(throwable: Throwable): ReplyMessage.Error {
val errorMessage = throwable.message ?: "Unknown error (empty message)"

val exceptionName = when (throwable) {
// Cancellation exceptions - User cancelled
is CreateCredentialCancellationException,
is GetCredentialCancellationException,
is NoCredentialException -> DOM_EXCEPTION_NOT_ALLOWED_ERROR

// Interruption exceptions - Operation aborted
is CreateCredentialInterruptedException,
is GetCredentialInterruptedException -> DOM_EXCEPTION_ABORT_ERROR

// Provider configuration exceptions - Not supported
is CreateCredentialProviderConfigurationException,
is GetCredentialProviderConfigurationException -> DOM_EXCEPTION_NOT_SUPPORTED_ERROR

// Unknown exceptions
is CreateCredentialUnknownException,
is GetCredentialUnknownException -> DOM_EXCEPTION_UNKNOWN_ERROR

// Default case for other exceptions
else -> DOM_EXCEPTION_NOT_ALLOWED_ERROR
}

return ReplyMessage.Error(
domExceptionMessage = errorMessage,
domExceptionName = exceptionName,
type = requestType
)
}

/**
* Sends a message to JavaScript via the reply proxy.
*/
@Throws (Throwable::class)
@SuppressLint("RequiresFeature", "Only called when feature is available")
private fun send(message: ReplyMessage) {
val methodTag = "$TAG:send"
try {
replyProxy.postMessage(message.toString())
} catch (t: Throwable) {
Logger.error(methodTag, "Reply message failed", t)
throw t
}
}
}
Loading
Loading