authenticate
Unified authentication method that automatically selects the appropriate API.
This method provides a single entry point for FIDO2 authentication that automatically chooses between Credential Manager and Google Play Services based on the FidoAuthenticateCustomizer.useFido2ApiClient setting on the authenticate { } block (default: auto-detected — Google Play Services when GMS is present, Credential Manager otherwise). It supports both discoverable and non-discoverable credential modes.
API Selection Logic:
if (customizer.useFido2ApiClient) {
// Use Google Play Services FIDO2
// - Better for non-discoverable credentials
// - Broader device compatibility
// - Explicit credential descriptors required
} else {
// Use Android Credential Manager
// - Better for discoverable credentials
// - Modern passkey experience
// - Automatic credential discovery
// - Required for conditional mediation (autofill with passkeys)
}Customization Options: The block parameter allows customization of the authentication request:
client.authenticate(options) {
// Optional: opt into Google Play Services for this call
useFido2ApiClient = true // For non-discoverable (device-bound) credentials
// For Google Play Services
onPublicKeyCredentialRequestOptions { options ->
options.toBuilder()
.setTimeoutSeconds(30.0)
.build()
}
// For Credential Manager
onGetPublicKeyCredentialOption { option ->
GetPublicKeyCredentialOption(
option.requestJson,
preferImmediatelyAvailableCredentials = true
)
}
}Return
A Result containing the assertion response on success, or exception on failure. The response format is consistent regardless of underlying API used.
Parameters
The WebAuthn-compatible authentication options containing challenge, timeout, rpId, and optionally allowCredentials
A customization function that allows modification of the request options before authentication. The block receives a FidoAuthenticateCustomizer with methods to customize both API types.