Skip to content

Instantly share code, notes, and snippets.

View tdcolvin's full-sized avatar

Tom Colvin tdcolvin

View GitHub Profile
val responseJson = credential.authenticationResponseJson
sendAuthenticationResponse(responseJson)
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
suspend fun getPasskeyAuthenticationRequestJson(username: String): String = withContext(
Dispatchers.IO) {
val url = HttpUrl.Builder()
.scheme("https")
.host("auth.tomcolvin.co.uk")
.addPathSegment("generate-authentication-options")
.addQueryParameter("username", username)
.build()
val request = Request.Builder()
.url(url)
export const expectedOrigin = [
`https://${rpID}`,
"android:apk-key-hash:H8aaJx3lOZCaxVnsZU5__ALkVjXJALA11rtegEE0Ldc", // signed using the keystore in the app folder
];
val responseJson = credential.authenticationResponseJson
sendAuthenticationResponse(responseJson)
suspend fun sendRegistrationResponse(
registrationResponseJson: String,
) = withContext(Dispatchers.IO) {
val url = HttpUrl.Builder()
.scheme("https")
.host("auth.tomcolvin.co.uk")
.addPathSegment("verify-registration")
.build()
val request = Request.Builder()
.url(url)
// 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
// Get the registration options from the auth server
suspend fun getPasskeyRegisterRequestJson(username: String): String
= withContext(Dispatchers.IO) {
val url = HttpUrl.Builder()
.scheme("https")
.host("auth.tomcolvin.co.uk")
.addPathSegment("generate-registration-options")
.addQueryParameter("username", username)
.build()
val localContext = LocalContext.current
val credentialManager = remember {
CredentialManager.create(localContext)
}