Credential
abstract class Credential
CustomCredential |
Base class for a custom credential with which the user consented to authenticate to the app. |
DigitalCredential |
Represents the user's digital credential, generally used for verification or sign-in purposes. |
PasswordCredential |
Represents the user's password credential granted by the user for app sign-in. |
PublicKeyCredential |
Represents the user's passkey credential granted by the user for app sign-in. |
RestoreCredential |
Represents the user's restore credential for the app sign in. |
Base class for a credential with which the user consented to authenticate to the app.
import androidx.credentials.Credential import androidx.credentials.CustomCredential import androidx.credentials.PasswordCredential import androidx.credentials.PublicKeyCredential when (credential) { is PublicKeyCredential -> { val responseJson = credential.authenticationResponseJson val userCredential = fidoAuthenticateWithServer(responseJson) loginWithPasskey(userCredential) } is PasswordCredential -> { val userName = credential.id val password = credential.password loginWithPassword(userName, password) } is CustomCredential -> { // If you are also using any external sign-in libraries, parse them here with the // utility functions provided they provided. if (credential.type == ExampleCustomCredential.TYPE) { try { val exampleCustomCredential = ExampleCustomCredential.createFrom(credential.data) loginWithExampleCustomCredential(exampleCustomCredential) } catch (e: ExampleCustomCredential.ExampleCustomCredentialParsingException) { // Unlikely to happen. If it does, you likely need to update the dependency // version of your external sign-in library. Log.e(TAG, "Failed to parse an ExampleCustomCredential", e) } } else { Log.w( TAG, "Received unrecognized credential type ${credential.type}. " + "This shouldn't happen", ) } } else -> { Log.w( TAG, "Received unrecognized credential type ${credential.type}. This shouldn't happen", ) } }
Summary
Public companion functions |
|
|---|---|
Credential |
@RequiresApi(value = 34)Parses the |
Credential |
createFrom(type: String, data: Bundle)Parses the raw data into an instance of |
Public properties |
|
|---|---|
Bundle |
the credential data in the |
String |
the credential type determined by the credential-type-specific subclass (e.g. |
Public companion functions
createFrom
@RequiresApi(value = 34)
fun createFrom(credential: Credential): Credential
Parses the credential into an instance of Credential.
It is recommended to construct a Credential by directly instantiating a Credential subclass, instead of using this API. This API should only be used by a small subset of system apps that reconstruct an existing object for user interactions such as collecting consents.
| Parameters | |
|---|---|
credential: Credential |
the framework Credential object |
createFrom
fun createFrom(type: String, data: Bundle): Credential
Parses the raw data into an instance of Credential.
It is recommended to construct a Credential by directly instantiating a Credential subclass, instead of using this API. This API should only be used by a small subset of system apps that reconstruct an existing object for user interactions such as collecting consents.
| Parameters | |
|---|---|
type: String |
matches |
data: Bundle |
matches |
Public properties
type
val type: String
the credential type determined by the credential-type-specific subclass (e.g. PasswordCredential.TYPE_PASSWORD_CREDENTIAL for PasswordCredential or PublicKeyCredential.TYPE_PUBLIC_KEY_CREDENTIAL for PublicKeyCredential)