# CredentialOption

Artifact: [androidx.credentials:credentials](https://developer.android.com/jetpack/androidx/releases/credentials) [View Source](https://cs.android.com/search?q=file:androidx/credentials/CredentialOption.kt+class:androidx.credentials.CredentialOption) Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/credentials#1.2.0)

*** ** * ** ***

<br />

```
abstract class CredentialOption
```

<br />

Known direct subclasses [GetCustomCredentialOption](https://developer.android.com/reference/kotlin/androidx/credentials/GetCustomCredentialOption), [GetDigitalCredentialOption](https://developer.android.com/reference/kotlin/androidx/credentials/GetDigitalCredentialOption), [GetPasswordOption](https://developer.android.com/reference/kotlin/androidx/credentials/GetPasswordOption), [GetPublicKeyCredentialOption](https://developer.android.com/reference/kotlin/androidx/credentials/GetPublicKeyCredentialOption), [GetRestoreCredentialOption](https://developer.android.com/reference/kotlin/androidx/credentials/GetRestoreCredentialOption)

|---|---|
| `https://developer.android.com/reference/kotlin/androidx/credentials/GetCustomCredentialOption` | Allows extending custom versions of GetCredentialOptions for unique use cases. |
| `https://developer.android.com/reference/kotlin/androidx/credentials/GetDigitalCredentialOption` | A request to retrieve the user's digital credential, normally used for verification or sign-in purpose. |
| `https://developer.android.com/reference/kotlin/androidx/credentials/GetPasswordOption` | A request to retrieve the user's saved application password from their password provider. |
| `https://developer.android.com/reference/kotlin/androidx/credentials/GetPublicKeyCredentialOption` | A request to get passkeys from the user's public key credential provider. |
| `https://developer.android.com/reference/kotlin/androidx/credentials/GetRestoreCredentialOption` | A request to get the restore credential from the restore credential provider. |

*** ** * ** ***

Base class for getting a specific type of credentials.

`https://developer.android.com/reference/kotlin/androidx/credentials/GetCredentialRequest` will be composed of a list of `https://developer.android.com/reference/kotlin/androidx/credentials/CredentialOption` subclasses to indicate the specific credential types and configurations that your app accepts.

The `https://developer.android.com/reference/kotlin/androidx/credentials/CredentialOption#typePriorityHint()` value helps decide where the credential will be displayed on the selector. It is used with more importance than signals like 'last recently used' but with less importance than other signals, such as the ordering of displayed accounts. It is expected to be one of the defined `https://developer.android.com/reference/kotlin/androidx/credentials/CredentialOption.PriorityHints` constants. By default, `https://developer.android.com/reference/kotlin/androidx/credentials/GetCustomCredentialOption` will have `https://developer.android.com/reference/kotlin/androidx/credentials/CredentialOption#PRIORITY_DEFAULT()`, `https://developer.android.com/reference/kotlin/androidx/credentials/GetPasswordOption` will have `https://developer.android.com/reference/kotlin/androidx/credentials/CredentialOption#PRIORITY_PASSWORD_OR_SIMILAR()` and `https://developer.android.com/reference/kotlin/androidx/credentials/GetPublicKeyCredentialOption` will have `https://developer.android.com/reference/kotlin/androidx/credentials/CredentialOption#PRIORITY_PASSKEY_OR_SIMILAR()`. It is expected that `https://developer.android.com/reference/kotlin/androidx/credentials/GetCustomCredentialOption` types will remain unchanged unless strong reasons arise and cannot ever have `https://developer.android.com/reference/kotlin/androidx/credentials/CredentialOption#PRIORITY_PASSKEY_OR_SIMILAR()`. Given passkeys prevent many security threats that other credentials do not, we enforce that nothing is shown higher than passkey types in order to provide end users with the safest credentials first. See the spec [here](https://w3c.github.io/webauthn/) for more information on passkeys.

## Summary

| ### Constants |
|---|---|
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/credentials/CredentialOption#PRIORITY_DEFAULT() = 2000` Default value of display priority. |
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/credentials/CredentialOption#PRIORITY_OIDC_OR_SIMILAR() = 500` Value of display priority for OpenID credentials or those of similar security level. |
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/credentials/CredentialOption#PRIORITY_PASSKEY_OR_SIMILAR() = 100` Value of display priority for passkeys or credentials of similar security level. |
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/credentials/CredentialOption#PRIORITY_PASSWORD_OR_SIMILAR() = 1000` Value of display priority for passwords or credentials of similar security level. |

| ### Public companion functions |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/credentials/CredentialOption` | `@https://developer.android.com/reference/kotlin/androidx/annotation/RequiresApi(value = 34) https://developer.android.com/reference/kotlin/androidx/credentials/CredentialOption#createFrom(android.credentials.CredentialOption)(option: https://developer.android.com/reference/android/credentials/CredentialOption.html)` Parses the `https://developer.android.com/reference/kotlin/androidx/credentials/CredentialOption.Companion#createFrom(android.credentials.CredentialOption)` into an instance of `https://developer.android.com/reference/kotlin/androidx/credentials/CredentialOption`. |
| `https://developer.android.com/reference/kotlin/androidx/credentials/CredentialOption` | `https://developer.android.com/reference/kotlin/androidx/credentials/CredentialOption#createFrom(kotlin.String,android.os.Bundle,android.os.Bundle,kotlin.Boolean,kotlin.collections.Set)( type: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html, requestData: https://developer.android.com/reference/android/os/Bundle.html, candidateQueryData: https://developer.android.com/reference/android/os/Bundle.html, requireSystemProvider: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html, allowedProviders: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-set/index.html<https://developer.android.com/reference/android/content/ComponentName.html> )` Parses the raw data into an instance of `https://developer.android.com/reference/kotlin/androidx/credentials/CredentialOption`. |

| ### Public properties |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-set/index.html<https://developer.android.com/reference/android/content/ComponentName.html>` | `https://developer.android.com/reference/kotlin/androidx/credentials/CredentialOption#allowedProviders()` a set of provider service `https://developer.android.com/reference/android/content/ComponentName.html` allowed to receive this option (Note: a `https://developer.android.com/reference/java/lang/SecurityException.html` will be thrown if it is set as non-empty but your app does not have android.permission.CREDENTIAL_MANAGER_SET_ALLOWED_PROVIDERS; empty means every provider is eligible; for API level \< 34, this property will not take effect and you should control the allowed provider via [library dependencies](https://developer.android.com/training/sign-in/passkeys#add-dependencies)) |
| `https://developer.android.com/reference/android/os/Bundle.html` | `https://developer.android.com/reference/kotlin/androidx/credentials/CredentialOption#candidateQueryData()` the partial request data in the `https://developer.android.com/reference/android/os/Bundle.html` format that will be sent to the provider during the initial candidate query stage, which will not contain sensitive user information |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/credentials/CredentialOption#isAutoSelectAllowed()` whether a credential entry will be automatically chosen if it is the only one available option |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/credentials/CredentialOption#isSystemProviderRequired()` true if must only be fulfilled by a system provider and false otherwise |
| `https://developer.android.com/reference/android/os/Bundle.html` | `https://developer.android.com/reference/kotlin/androidx/credentials/CredentialOption#requestData()` the request data in the `https://developer.android.com/reference/android/os/Bundle.html` format |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | `https://developer.android.com/reference/kotlin/androidx/credentials/CredentialOption#type()` the credential type determined by the credential-type-specific subclass (e.g. the type for `https://developer.android.com/reference/kotlin/androidx/credentials/GetPasswordOption` is `https://developer.android.com/reference/kotlin/androidx/credentials/PasswordCredential#TYPE_PASSWORD_CREDENTIAL()` and for `https://developer.android.com/reference/kotlin/androidx/credentials/GetPublicKeyCredentialOption` is `https://developer.android.com/reference/kotlin/androidx/credentials/PublicKeyCredential#TYPE_PUBLIC_KEY_CREDENTIAL()`) |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/credentials/CredentialOption#typePriorityHint()` sets the priority of this entry, which defines how it appears in the credential selector, with less precedence than account ordering but more precedence than last used time; see `https://developer.android.com/reference/kotlin/androidx/credentials/CredentialOption.PriorityHints` for more information |

## Constants

### PRIORITY_DEFAULT

```
const val PRIORITY_DEFAULT = 2000: Int
```

Default value of display priority.

### PRIORITY_OIDC_OR_SIMILAR

```
const val PRIORITY_OIDC_OR_SIMILAR = 500: Int
```

Value of display priority for OpenID credentials or those of similar security level.

### PRIORITY_PASSKEY_OR_SIMILAR

```
const val PRIORITY_PASSKEY_OR_SIMILAR = 100: Int
```

Value of display priority for passkeys or credentials of similar security level.

### PRIORITY_PASSWORD_OR_SIMILAR

```
const val PRIORITY_PASSWORD_OR_SIMILAR = 1000: Int
```

Value of display priority for passwords or credentials of similar security level.

## Public companion functions

### createFrom

Added in [1.5.0](https://developer.android.com/jetpack/androidx/releases/credentials#1.5.0)

```
@RequiresApi(value = 34)
fun createFrom(option: CredentialOption): CredentialOption
```

Parses the `https://developer.android.com/reference/kotlin/androidx/credentials/CredentialOption.Companion#createFrom(android.credentials.CredentialOption)` into an instance of `https://developer.android.com/reference/kotlin/androidx/credentials/CredentialOption`.

It is recommended to construct a CredentialOption by directly instantiating a CredentialOption 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 |
|---|---|
| `option: https://developer.android.com/reference/android/credentials/CredentialOption.html` | the framework CredentialOption object |

### createFrom

Added in [1.5.0](https://developer.android.com/jetpack/androidx/releases/credentials#1.5.0)

```
fun createFrom(
    type: String,
    requestData: Bundle,
    candidateQueryData: Bundle,
    requireSystemProvider: Boolean,
    allowedProviders: Set<ComponentName>
): CredentialOption
```

Parses the raw data into an instance of `https://developer.android.com/reference/kotlin/androidx/credentials/CredentialOption`.

It is recommended to construct a CredentialOption by directly instantiating a CredentialOption 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: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | matches `https://developer.android.com/reference/kotlin/androidx/credentials/CredentialOption#type()` |
| `requestData: https://developer.android.com/reference/android/os/Bundle.html` | matches `https://developer.android.com/reference/kotlin/androidx/credentials/CredentialOption#requestData()`, the request data in the `https://developer.android.com/reference/android/os/Bundle.html` format; this should be constructed and retrieved from the a given `https://developer.android.com/reference/kotlin/androidx/credentials/CredentialOption` itself and never be created from scratch |
| `candidateQueryData: https://developer.android.com/reference/android/os/Bundle.html` | matches `https://developer.android.com/reference/kotlin/androidx/credentials/CredentialOption#candidateQueryData()`; this should be constructed and retrieved from the a given `https://developer.android.com/reference/kotlin/androidx/credentials/CredentialOption` itself and never be created from scratch |
| `requireSystemProvider: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | matches `https://developer.android.com/reference/kotlin/androidx/credentials/CredentialOption#isSystemProviderRequired()` |
| `allowedProviders: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-set/index.html<https://developer.android.com/reference/android/content/ComponentName.html>` | matches `https://developer.android.com/reference/kotlin/androidx/credentials/CredentialOption#allowedProviders()`, empty means every provider is eligible |

## Public properties

### allowedProviders

Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/credentials#1.2.0)

```
val allowedProviders: Set<ComponentName>
```

a set of provider service `https://developer.android.com/reference/android/content/ComponentName.html` allowed to receive this option (Note: a `https://developer.android.com/reference/java/lang/SecurityException.html` will be thrown if it is set as non-empty but your app does not have android.permission.CREDENTIAL_MANAGER_SET_ALLOWED_PROVIDERS; empty means every provider is eligible; for API level \< 34, this property will not take effect and you should control the allowed provider via [library dependencies](https://developer.android.com/training/sign-in/passkeys#add-dependencies))

### candidateQueryData

Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/credentials#1.2.0)

```
val candidateQueryData: Bundle
```

the partial request data in the `https://developer.android.com/reference/android/os/Bundle.html` format that will be sent to the provider during the initial candidate query stage, which will not contain sensitive user information

### isAutoSelectAllowed

Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/credentials#1.2.0)

```
val isAutoSelectAllowed: Boolean
```

whether a credential entry will be automatically chosen if it is the only one available option

### isSystemProviderRequired

Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/credentials#1.2.0)

```
val isSystemProviderRequired: Boolean
```

true if must only be fulfilled by a system provider and false otherwise

### requestData

Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/credentials#1.2.0)

```
val requestData: Bundle
```

the request data in the `https://developer.android.com/reference/android/os/Bundle.html` format

### type

Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/credentials#1.2.0)

```
val type: String
```

the credential type determined by the credential-type-specific subclass (e.g. the type for `https://developer.android.com/reference/kotlin/androidx/credentials/GetPasswordOption` is `https://developer.android.com/reference/kotlin/androidx/credentials/PasswordCredential#TYPE_PASSWORD_CREDENTIAL()` and for `https://developer.android.com/reference/kotlin/androidx/credentials/GetPublicKeyCredentialOption` is `https://developer.android.com/reference/kotlin/androidx/credentials/PublicKeyCredential#TYPE_PUBLIC_KEY_CREDENTIAL()`)

### typePriorityHint

Added in [1.3.0](https://developer.android.com/jetpack/androidx/releases/credentials#1.3.0)

```
val typePriorityHint: Int
```

sets the priority of this entry, which defines how it appears in the credential selector, with less precedence than account ordering but more precedence than last used time; see `https://developer.android.com/reference/kotlin/androidx/credentials/CredentialOption.PriorityHints` for more information