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 configuration and availability. It supports both discoverable and non-discoverable credential modes.
API Selection Logic:
if (config.useFido2Client) {
// 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
}Customization Options: The block parameter allows customization of the authentication request:
client.authenticate(options) {
// 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 Fido2AuthenticateCustomizer with methods to customize both API types.