This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| val responseJson = credential.authenticationResponseJson | |
| sendAuthenticationResponse(responseJson) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export const expectedOrigin = [ | |
| `https://${rpID}`, | |
| "android:apk-key-hash:H8aaJx3lOZCaxVnsZU5__ALkVjXJALA11rtegEE0Ldc", // signed using the keystore in the app folder | |
| ]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [ | |
| { | |
| "relation" : [ | |
| "delegate_permission/common.handle_all_urls", | |
| "delegate_permission/common.get_login_creds" | |
| ], | |
| "target" : { | |
| "namespace" : "android_app", | |
| "package_name" : "com.tdcolvin.passkeyauthdemo", | |
| "sha256_cert_fingerprints" : [ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| val responseJson = credential.authenticationResponseJson | |
| sendAuthenticationResponse(responseJson) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| val localContext = LocalContext.current | |
| val credentialManager = remember { | |
| CredentialManager.create(localContext) | |
| } |
NewerOlder