CreateCredentialResponse


abstract class CreateCredentialResponse

Known direct subclasses
CreateCustomCredentialResponse

Base custom create response class for the credential creation operation made with the CreateCustomCredentialRequest.

CreateDigitalCredentialResponse

A response of creating a digital credential.

CreatePasswordResponse

A response of a password saving flow.

CreatePublicKeyCredentialResponse

A response of a public key credential (passkey) flow.

CreateRestoreCredentialResponse

A response of the RestoreCredential flow.


Base response class for the credential creation operation made with the CreateCredentialRequest.

import androidx.credentials.CreateCustomCredentialResponse
import androidx.credentials.CreatePasswordResponse
import androidx.credentials.CreatePublicKeyCredentialResponse
import androidx.credentials.Credential
import androidx.credentials.CustomCredential
import androidx.credentials.PublicKeyCredential

when (response) {
    is CreatePasswordResponse ->
        // Password saved successfully, proceed to signed in experience.
        loginWithPassword()
    is CreatePublicKeyCredentialResponse ->
        // Validate and register the registration json from your server, and if successful
        // proceed to signed in experience.
        loginWithPasskey(response.registrationResponseJson)
    is CreateCustomCredentialResponse -> {
        // If you are also using any external sign-in libraries, parse them here with the
        // utility functions provided they provided.
        if (response.type == ExampleCustomCredential.TYPE) {
            try {
                val createExampleCustomCredentialResponse =
                    CreateExampleCustomCredentialResponse.createFrom(response)
                loginWithExampleCustomCredential(createExampleCustomCredentialResponse)
            } catch (e: CreateExampleCustomCredentialResponse.ParsingException) {
                // 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 a CreateExampleCustomCredentialResponse", e)
            }
        } else {
            Log.w(
                TAG,
                "Received unrecognized response type ${response.type}. " +
                    "This shouldn't happen",
            )
        }
    }
    else -> {
        Log.w(
            TAG,
            "Received unrecognized response type ${response.type}. This shouldn't happen",
        )
    }
}

Summary

Public companion functions

CreateCredentialResponse
createFrom(type: String, data: Bundle)

Parses the raw data into an instance of CreateCredentialResponse.

Public properties

Bundle

the response data in the Bundle format

String

the credential type determined by the credential-type-specific subclass (e.g. the type for CreatePasswordResponse is PasswordCredential.TYPE_PASSWORD_CREDENTIAL and for CreatePublicKeyCredentialResponse is PublicKeyCredential.TYPE_PUBLIC_KEY_CREDENTIAL)

Public companion functions

createFrom

Added in 1.6.0
fun createFrom(type: String, data: Bundle): CreateCredentialResponse

Parses the raw data into an instance of CreateCredentialResponse.

It is recommended to construct a CreateCredentialResponse by directly instantiating a CreateCredentialResponse subclass, instead of using this API. This API should only be used by a small subset of system apps that reconstruct an existing object across IPC.

Parameters
type: String

matches CreateCredentialResponse.type, the credential type of the response

data: Bundle

matches CreateCredentialResponse.data, the credential response data in the Bundle format; this should be constructed and retrieved from the a given CreateCredentialResponse itself and never be created from scratch

Public properties

data

Added in 1.2.0
val data: Bundle

the response data in the Bundle format

type

Added in 1.2.0
val type: String

the credential type determined by the credential-type-specific subclass (e.g. the type for CreatePasswordResponse is PasswordCredential.TYPE_PASSWORD_CREDENTIAL and for CreatePublicKeyCredentialResponse is PublicKeyCredential.TYPE_PUBLIC_KEY_CREDENTIAL)