Skip to content

Instantly share code, notes, and snippets.

@tdcolvin
Last active May 8, 2025 15:54
Show Gist options
  • Select an option

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

Select an option

Save tdcolvin/7a47ca42e5be249a4b94ef8ef6c3e201 to your computer and use it in GitHub Desktop.
// Get the registration options.
// 'username' here is the requested username for the new account
val registerRequestJson = getPasskeyRegisterRequestJson(username)
// Create an object which holds the options needed to create the passkey
val createPublicKeyCredentialRequest = CreatePublicKeyCredentialRequest(
requestJson = registerRequestJson,
// Pop up a UI
preferImmediatelyAvailableCredentials = false
)
// Finally show the UI, and guide the user to creating the passkey
val createCredentialResponse = credentialManager.createCredential(
context = localActivity,
request = createPublicKeyCredentialRequest
)
// Make sure Credential Manager created the right kind of credential
if (createCredentialResponse !is CreatePublicKeyCredentialResponse) {
throw Exception("Incorrect response type")
}
// The response is sent back to the server
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment