Skip to content

Instantly share code, notes, and snippets.

@tdcolvin
Created May 10, 2025 11:51
Show Gist options
  • Select an option

  • Save tdcolvin/a88cd75094e05ec3b336e89e1b923a75 to your computer and use it in GitHub Desktop.

Select an option

Save tdcolvin/a88cd75094e05ec3b336e89e1b923a75 to your computer and use it in GitHub Desktop.
val localActivity = LocalActivity.current
...
// Get the authentication request JSON from the server, using the code above
val authenticationRequestJson = getPasskeyAuthenticationRequestJson(username)
// Build the request for Credential Manager
val getPublicKeyCredentialOption = GetPublicKeyCredentialOption(
requestJson = authenticationRequestJson
)
val signInRequest = GetCredentialRequest(listOf(getPublicKeyCredentialOption))
// Ask Credential Manager to process the sign-in request
// This will pop up a dialog asking the user for their biometrics or PIN
// (hence the need to pass in the activity)
val result = credentialManager.getCredential(
context = localActivity,
request = signInRequest
)
val credential = result.credential
// Check that the returned credential is a passkey (PublicKeyCredential)
if (credential !is PublicKeyCredential) {
throw Exception("Incorrect credential type")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment