Skip to content

Commit c8dfc10

Browse files
Minor updates to snippets for doc restructuring (#665)
* Minor updates to snippets for doc restructuring Made the following changes: - Updated comments for clarity - Replaced random example values with placeholders - Added SignInJsonRequest * Initialize preferImmediatelyAvailableCredentials * Update PasskeyAndPasswordFunctions.kt * Update PasskeyAndPasswordFunctions.kt * Update libs.versions.toml * Update PasskeyAndPasswordFunctions.kt * Update PasskeyAndPasswordFunctions.kt * Update PasskeyAndPasswordFunctions.kt * Update PasskeyAndPasswordFunctions.kt * Update jsonSnippets.json * Minor updates to snippets for doc restructuring Made the following changes: - Updated comments for clarity - Replaced random example values with placeholders - Added SignInJsonRequest * Initialize preferImmediatelyAvailableCredentials * Update PasskeyAndPasswordFunctions.kt * Update PasskeyAndPasswordFunctions.kt * Update libs.versions.toml * Update PasskeyAndPasswordFunctions.kt * Update PasskeyAndPasswordFunctions.kt * Update PasskeyAndPasswordFunctions.kt * Update PasskeyAndPasswordFunctions.kt * Update jsonSnippets.json * Update jsonSnippets.json * Update jsonSnippets.json
1 parent cfdb6a9 commit c8dfc10

File tree

3 files changed

+52
-46
lines changed

3 files changed

+52
-46
lines changed

gradle/libs.versions.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ androidx-constraintlayout = "2.2.1"
1212
androidx-constraintlayout-compose = "1.1.1"
1313
androidx-coordinator-layout = "1.3.0"
1414
androidx-corektx = "1.17.0"
15-
androidx-credentials = "1.5.0"
16-
androidx-credentials-play-services-auth = "1.5.0"
15+
androidx-credentials = "1.6.0-beta03"
16+
androidx-credentials-play-services-auth = "1.6.0-beta03"
1717
androidx-emoji2-views = "1.6.0"
1818
androidx-fragment-ktx = "1.8.9"
1919
androidx-glance-appwidget = "1.1.1"

identity/credentialmanager/src/main/java/com/example/identity/credentialmanager/PasskeyAndPasswordFunctions.kt

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -70,19 +70,23 @@ class PasskeyAndPasswordFunctions(
7070
) {
7171
val requestJson = creationResult.toString()
7272
// [START android_identity_get_password_passkey_options]
73-
// Retrieves the user's saved password for your app from their
74-
// password provider.
73+
// Get password logins from the credential provider on the user's device.
7574
val getPasswordOption = GetPasswordOption()
7675

77-
// Get passkey from the user's public key credential provider.
76+
// Get passkeys from the credential provider on the user's device.
7877
val getPublicKeyCredentialOption = GetPublicKeyCredentialOption(
7978
requestJson = requestJson
8079
)
8180
// [END android_identity_get_password_passkey_options]
8281
var result: GetCredentialResponse
82+
var preferImmediatelyAvailableCredentials: Boolean = false
8383
// [START android_identity_get_credential_request]
8484
val credentialRequest = GetCredentialRequest(
85+
// Include all the sign-in options that your app supports.
8586
listOf(getPasswordOption, getPublicKeyCredentialOption),
87+
// Defines whether you prefer to use only immediately available
88+
// credentials or hybrid credentials.
89+
preferImmediatelyAvailableCredentials = preferImmediatelyAvailableCredentials
8690
)
8791
// [END android_identity_get_credential_request]
8892
runBlocking {
@@ -92,7 +96,8 @@ class PasskeyAndPasswordFunctions(
9296
val response = credentialManager.prepareGetCredential(
9397
GetCredentialRequest(
9498
listOf(
95-
getPublicKeyCredentialOption,
99+
// Include all the sign-in options that your app supports
100+
getPublicKeyCredentialOption,
96101
getPasswordOption
97102
)
98103
)
@@ -230,19 +235,19 @@ class PasskeyAndPasswordFunctions(
230235

231236
// [START android_identity_create_passkey]
232237
suspend fun createPasskey(requestJson: String, preferImmediatelyAvailableCredentials: Boolean) {
238+
var isConditional: Boolean = false
233239
val createPublicKeyCredentialRequest = CreatePublicKeyCredentialRequest(
234-
// Contains the request in JSON format. Uses the standard WebAuthn
235-
// web JSON spec.
240+
// Contains the request in JSON format.
236241
requestJson = requestJson,
237-
// Defines whether you prefer to use only immediately available
238-
// credentials, not hybrid credentials, to fulfill this request.
239-
// This value is false by default.
242+
// Defines whether you prefer to use only locally-available
243+
// credentials or hybrid credentials.
240244
preferImmediatelyAvailableCredentials = preferImmediatelyAvailableCredentials,
245+
// Automatically create a passkey if the user does not have one.
246+
isConditional = isConditional
241247
)
242248

243-
// Execute CreateCredentialRequest asynchronously to register credentials
244-
// for a user account. Handle success and failure cases with the result and
245-
// exceptions, respectively.
249+
// Execute createCredential asynchronously to register credentials
250+
// for a user account.
246251
coroutineScope {
247252
try {
248253
val result = credentialManager.createCredential(

identity/credentialmanager/src/main/jsonSnippets.json

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"namespace": "android_app",
3131
"package_name": "com.example.android",
3232
"sha256_cert_fingerprints": [
33-
SHA_HEX_VALUE
33+
"<SHA_HEX_VALUE>"
3434
]
3535
}
3636
}
@@ -57,14 +57,14 @@
5757
// JSON response format
5858
// [START android_identity_format_json_response_passkey]
5959
{
60-
"id": "KEDetxZcUfinhVi6Za5nZQ",
60+
"id": "<credential ID>",
6161
"type": "public-key",
62-
"rawId": "KEDetxZcUfinhVi6Za5nZQ",
62+
"rawId": "<raw credential ID>",
6363
"response": {
64-
"clientDataJSON": "eyJ0eXBlIjoid2ViYXV0aG4uZ2V0IiwiY2hhbGxlbmdlIjoiVDF4Q3NueE0yRE5MMktkSzVDTGE2Zk1oRDdPQnFobzZzeXpJbmtfbi1VbyIsIm9yaWdpbiI6ImFuZHJvaWQ6YXBrLWtleS1oYXNoOk1MTHpEdll4UTRFS1R3QzZVNlpWVnJGUXRIOEdjVi0xZDQ0NEZLOUh2YUkiLCJhbmRyb2lkUGFja2FnZU5hbWUiOiJjb20uZ29vZ2xlLmNyZWRlbnRpYWxtYW5hZ2VyLnNhbXBsZSJ9",
65-
"authenticatorData": "j5r_fLFhV-qdmGEwiukwD5E_5ama9g0hzXgN8thcFGQdAAAAAA",
66-
"signature": "MEUCIQCO1Cm4SA2xiG5FdKDHCJorueiS04wCsqHhiRDbbgITYAIgMKMFirgC2SSFmxrh7z9PzUqr0bK1HZ6Zn8vZVhETnyQ",
67-
"userHandle": "2HzoHm_hY0CjuEESY9tY6-3SdjmNHOoNqaPDcZGzsr0"
64+
"clientDataJSON": "<signed client data containing challenge>",
65+
"authenticatorData": "<authenticator metadata>",
66+
"signature": "<digital signature to be verified>",
67+
"userHandle": "<user ID from credential registration>"
6868
}
6969
}
7070
// [END android_identity_format_json_response_passkey]
@@ -74,40 +74,30 @@
7474
// Json request for creating a passkey
7575
// [START android_identity_create_passkey_request_json]
7676
{
77-
"challenge": "abc123",
77+
"challenge": "<base64url-encoded challenge>",
7878
"rp": {
79-
"name": "Credential Manager example",
80-
"id": "credential-manager-test.example.com"
79+
"name": "<relying party name>",
80+
"id": "<relying party host name>"
8181
},
8282
"user": {
83-
"id": "def456",
84-
"name": "helloandroid@gmail.com",
85-
"displayName": "helloandroid@gmail.com"
83+
"id": "<base64url-encoded user ID>",
84+
"name": "<user name>",
85+
"displayName": "<user display name>"
8686
},
8787
"pubKeyCredParams": [
8888
{
8989
"type": "public-key",
9090
"alg": -7
91-
},
92-
{
93-
"type": "public-key",
94-
"alg": -257
9591
}
9692
],
97-
"timeout": 1800000,
9893
"attestation": "none",
9994
"excludeCredentials": [
10095
{
101-
"id": "ghi789",
102-
"type": "public-key"
103-
},
104-
{
105-
"id": "jkl012",
106-
"type": "public-key"
96+
"id": "<base64url-encoded credential ID to exclude>",
97+
"type": "public-key"
10798
}
10899
],
109100
"authenticatorSelection": {
110-
"authenticatorAttachment": "platform",
111101
"requireResidentKey": true,
112102
"residentKey": "required",
113103
"userVerification": "required"
@@ -120,16 +110,27 @@
120110
// Json response when creating a passkey
121111
// [START android_identity_create_passkey_response_json]
122112
{
123-
"id": "KEDetxZcUfinhVi6Za5nZQ",
113+
"id": "<identifier>",
124114
"type": "public-key",
125-
"rawId": "KEDetxZcUfinhVi6Za5nZQ",
115+
"rawId": "<identifier>",
126116
"response": {
127-
"clientDataJSON": "eyJ0eXBlIjoid2ViYXV0aG4uY3JlYXRlIiwiY2hhbGxlbmdlIjoibmhrUVhmRTU5SmI5N1Z5eU5Ka3ZEaVh1Y01Fdmx0ZHV2Y3JEbUdyT0RIWSIsIm9yaWdpbiI6ImFuZHJvaWQ6YXBrLWtleS1oYXNoOk1MTHpEdll4UTRFS1R3QzZVNlpWVnJGUXRIOEdjVi0xZDQ0NEZLOUh2YUkiLCJhbmRyb2lkUGFja2FnZU5hbWUiOiJjb20uZ29vZ2xlLmNyZWRlbnRpYWxtYW5hZ2VyLnNhbXBsZSJ9",
128-
"attestationObject": "o2NmbXRkbm9uZWdhdHRTdG10oGhhdXRoRGF0YViUj5r_fLFhV-qdmGEwiukwD5E_5ama9g0hzXgN8thcFGRdAAAAAAAAAAAAAAAAAAAAAAAAAAAAEChA3rcWXFH4p4VYumWuZ2WlAQIDJiABIVgg4RqZaJyaC24Pf4tT-8ONIZ5_Elddf3dNotGOx81jj3siWCAWXS6Lz70hvC2g8hwoLllOwlsbYatNkO2uYFO-eJID6A"
129-
}
117+
"clientDataJSON": "<ArrayBuffer encoded object with the origin and signed challenge>",
118+
"attestationObject": "<ArrayBuffer encoded object with the public key and other information.>"
119+
},
120+
"authenticatorAttachment": "platform"
130121
}
131122
// [END android_identity_create_passkey_response_json]
132-
}
133-
123+
},
124+
{
125+
"SignInJsonRequest":
126+
//Json object sent by server when creating sign-in request
127+
// [START android_identity_create_sign_in_request_json]
128+
{
129+
"challenge": "<your app challenge>",
130+
"allowCredentials": [],
131+
"rpId": "<your app server domain>"
132+
}
133+
// [END android_identity_create_sign_in_request_json]
134+
}
134135
]
135136
}

0 commit comments

Comments
 (0)