# GetPublicKeyCredentialOption

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

*** ** * ** ***

<br />

```
public final class GetPublicKeyCredentialOption extends CredentialOption
```

<br />

|---|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object.html) |||
| ↳ | [androidx.credentials.CredentialOption](https://developer.android.com/reference/androidx/credentials/CredentialOption) ||
|   | ↳ | [androidx.credentials.GetPublicKeyCredentialOption](https://developer.android.com/reference/androidx/credentials/GetPublicKeyCredentialOption) |

*** ** * ** ***

A request to get passkeys from the user's public key credential provider.

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/credentials/GetPublicKeyCredentialOption#GetPublicKeyCredentialOption(kotlin.String,kotlin.ByteArray,kotlin.collections.Set)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html requestJson, byte[] clientDataHash, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/Set.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/content/ComponentName.html> allowedProviders )` Constructs a `https://developer.android.com/reference/androidx/credentials/GetPublicKeyCredentialOption`. |

| ### Public methods |
|---|---|
| `final byte[]` | `https://developer.android.com/reference/androidx/credentials/GetPublicKeyCredentialOption#getClientDataHash()()` a clientDataHash value to sign over in place of assembling and hashing clientDataJSON during the signature request; meaningful only if you have set the `https://developer.android.com/reference/androidx/credentials/GetCredentialRequest#origin()` |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/credentials/GetPublicKeyCredentialOption#getRequestJson()()` the request in JSON format in the standard webauthn web json shown [here](https://w3c.github.io/webauthn/#dictdef-publickeycredentialrequestoptionsjson). |

### Inherited methods

From [androidx.credentials.CredentialOption](https://developer.android.com/reference/androidx/credentials/CredentialOption) `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/Set.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/content/ComponentName.html>` `https://developer.android.com/reference/androidx/credentials/CredentialOption#getAllowedProviders()()`

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))
`final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/os/Bundle.html` `https://developer.android.com/reference/androidx/credentials/CredentialOption#getCandidateQueryData()()`

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
`final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/os/Bundle.html` `https://developer.android.com/reference/androidx/credentials/CredentialOption#getRequestData()()`

the request data in the `https://developer.android.com/reference/android/os/Bundle.html` format
`final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html` `https://developer.android.com/reference/androidx/credentials/CredentialOption#getType()()`

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

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/androidx/credentials/CredentialOption.PriorityHints` for more information
`final boolean` `https://developer.android.com/reference/androidx/credentials/CredentialOption#isAutoSelectAllowed()()`

whether a credential entry will be automatically chosen if it is the only one available option
`final boolean` `https://developer.android.com/reference/androidx/credentials/CredentialOption#isSystemProviderRequired()()`

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

## Public constructors

### GetPublicKeyCredentialOption

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

```
public GetPublicKeyCredentialOption(
    @NonNull String requestJson,
    byte[] clientDataHash,
    @NonNull Set<@NonNull ComponentName> allowedProviders
)
```

Constructs a `https://developer.android.com/reference/androidx/credentials/GetPublicKeyCredentialOption`.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html requestJson` | the request in JSON format in the standard webauthn web json shown [here](https://w3c.github.io/webauthn/#dictdef-publickeycredentialrequestoptionsjson). |
| `byte[] clientDataHash` | a clientDataHash value to sign over in place of assembling and hashing clientDataJSON during the signature request; set only if you have set the `https://developer.android.com/reference/androidx/credentials/GetCredentialRequest#origin()` |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/Set.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/content/ComponentName.html> 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; 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)) |

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-null-pointer-exception/index.html` | If `https://developer.android.com/reference/androidx/credentials/GetPublicKeyCredentialOption#(kotlin.String,kotlin.ByteArray,kotlin.collections.Set)` is null |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-argument-exception/index.html` | If `https://developer.android.com/reference/androidx/credentials/GetPublicKeyCredentialOption#(kotlin.String,kotlin.ByteArray,kotlin.collections.Set)` is empty, or if it is not a valid JSON |

## Public methods

### getClientDataHash

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

```
public final byte[] getClientDataHash()
```

a clientDataHash value to sign over in place of assembling and hashing clientDataJSON during the signature request; meaningful only if you have set the `https://developer.android.com/reference/androidx/credentials/GetCredentialRequest#origin()`

### getRequestJson

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

```
public final @NonNull String getRequestJson()
```

the request in JSON format in the standard webauthn web json shown [here](https://w3c.github.io/webauthn/#dictdef-publickeycredentialrequestoptionsjson).