Skip to content

Commit 85f9718

Browse files
committed
Made the realm parameter optional in passkey
1 parent d58083d commit 85f9718

File tree

3 files changed

+18
-28
lines changed

3 files changed

+18
-28
lines changed

auth0/src/main/java/com/auth0/android/authentication/AuthenticationAPIClient.kt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -176,18 +176,18 @@ public class AuthenticationAPIClient @VisibleForTesting(otherwise = VisibleForTe
176176
*
177177
* @param authSession the auth session received from the server as part of the public key challenge request.
178178
* @param authResponse the public key credential authentication response
179-
* @param realm the default connection to use
179+
* @param realm the connection to use. If excluded, the application will use the default connection configured in the tenant
180180
* @return a request to configure and start that will yield [Credentials]
181181
*/
182182
public fun signinWithPasskey(
183183
authSession: String,
184184
authResponse: PublicKeyCredentials,
185-
realm: String
185+
realm: String? = null
186186
): AuthenticationRequest {
187187
val params = ParameterBuilder.newBuilder().apply {
188188
setGrantType(ParameterBuilder.GRANT_TYPE_PASSKEY)
189189
set(AUTH_SESSION_KEY, authSession)
190-
setRealm(realm)
190+
realm?.let { setRealm(it) }
191191
}.asDictionary()
192192

193193
return loginWithToken(params)
@@ -217,12 +217,12 @@ public class AuthenticationAPIClient @VisibleForTesting(otherwise = VisibleForTe
217217
* ```
218218
*
219219
* @param userData user information of the client
220-
* @param realm default connection to use
220+
* @param realm the connection to use. If excluded, the application will use the default connection configured in the tenant
221221
* @return a request to configure and start that will yield [PasskeyRegistrationChallenge]
222222
*/
223223
public fun signupWithPasskey(
224224
userData: UserData,
225-
realm: String
225+
realm: String? = null
226226
): Request<PasskeyRegistrationChallenge, AuthenticationException> {
227227
val user = Gson().toJsonTree(userData)
228228
val url = auth0.getDomainUrl().toHttpUrl().newBuilder()
@@ -232,7 +232,7 @@ public class AuthenticationAPIClient @VisibleForTesting(otherwise = VisibleForTe
232232

233233
val params = ParameterBuilder.newBuilder().apply {
234234
setClientId(clientId)
235-
setRealm(realm)
235+
realm?.let { setRealm(it) }
236236
}.asDictionary()
237237

238238
val passkeyRegistrationChallengeAdapter: JsonAdapter<PasskeyRegistrationChallenge> =
@@ -261,11 +261,11 @@ public class AuthenticationAPIClient @VisibleForTesting(otherwise = VisibleForTe
261261
* })
262262
* ```
263263
*
264-
* @param realm A default connection name
264+
* @param realm the connection to use. If excluded, the application will use the default connection configured in the tenant
265265
* @return a request to configure and start that will yield [PasskeyChallenge]
266266
*/
267267
public fun passkeyChallenge(
268-
realm: String
268+
realm: String? = null
269269
): Request<PasskeyChallenge, AuthenticationException> {
270270
val url = auth0.getDomainUrl().toHttpUrl().newBuilder()
271271
.addPathSegment(PASSKEY_PATH)
@@ -274,7 +274,7 @@ public class AuthenticationAPIClient @VisibleForTesting(otherwise = VisibleForTe
274274

275275
val parameters = ParameterBuilder.newBuilder().apply {
276276
setClientId(clientId)
277-
setRealm(realm)
277+
realm?.let { setRealm(it) }
278278
}.asDictionary()
279279

280280
val passkeyChallengeAdapter: JsonAdapter<PasskeyChallenge> = GsonAdapter(

auth0/src/main/java/com/auth0/android/provider/PasskeyManager.kt

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,6 @@ internal class PasskeyManager(
5454
callback: Callback<Credentials, AuthenticationException>,
5555
executor: Executor = Executors.newSingleThreadExecutor()
5656
) {
57-
58-
if (realm == null) {
59-
callback.onFailure(AuthenticationException("Realm is required for passkey authentication"))
60-
return
61-
}
6257
authenticationAPIClient.signupWithPasskey(userData, realm)
6358
.addParameters(parameters)
6459
.start(object : Callback<PasskeyRegistrationChallenge, AuthenticationException> {
@@ -120,10 +115,6 @@ internal class PasskeyManager(
120115
callback: Callback<Credentials, AuthenticationException>,
121116
executor: Executor = Executors.newSingleThreadExecutor()
122117
) {
123-
if (realm == null) {
124-
callback.onFailure(AuthenticationException("Realm is required for passkey authentication"))
125-
return
126-
}
127118
authenticationAPIClient.passkeyChallenge(realm)
128119
.start(object : Callback<PasskeyChallenge, AuthenticationException> {
129120
override fun onSuccess(result: PasskeyChallenge) {

sample/src/main/java/com/auth0/sample/DatabaseLoginFragment.kt

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ class DatabaseLoginFragment : Fragment() {
120120
}
121121

122122
binding.btSignupPasskey.setOnClickListener {
123-
passkeySignup()
123+
passkeySignup(binding.textEmail.text.toString())
124124
}
125125

126126
binding.btSignInPasskey.setOnClickListener {
@@ -129,7 +129,7 @@ class DatabaseLoginFragment : Fragment() {
129129

130130
binding.btSignupPasskeyAsync.setOnClickListener {
131131
launchAsync {
132-
passkeySignupAsync()
132+
passkeySignupAsync(binding.textEmail.text.toString())
133133
}
134134
}
135135

@@ -486,11 +486,11 @@ class DatabaseLoginFragment : Fragment() {
486486
}
487487
}
488488

489-
private fun passkeySignup() {
489+
private fun passkeySignup(email: String) {
490490
authenticationApiClient.signupWithPasskey(
491491
UserData(
492-
email = "jndoe@email.com"
493-
), "Username-Password-Authentication"
492+
email = email
493+
)
494494
).start(object : Callback<PasskeyRegistrationChallenge, AuthenticationException> {
495495
override fun onSuccess(result: PasskeyRegistrationChallenge) {
496496
val passKeyRegistrationChallenge = result
@@ -558,7 +558,7 @@ class DatabaseLoginFragment : Fragment() {
558558
}
559559

560560
private fun passkeySignin() {
561-
authenticationApiClient.passkeyChallenge("Username-Password-Authentication")
561+
authenticationApiClient.passkeyChallenge()
562562
.start(object : Callback<PasskeyChallenge, AuthenticationException> {
563563
override fun onSuccess(result: PasskeyChallenge) {
564564
val passkeyChallengeResponse = result
@@ -631,12 +631,11 @@ class DatabaseLoginFragment : Fragment() {
631631
})
632632
}
633633

634-
private suspend fun passkeySignupAsync() {
634+
private suspend fun passkeySignupAsync(email: String) {
635635

636636
try {
637637
val challenge = authenticationApiClient.signupWithPasskey(
638-
UserData(email = "[email protected]"),
639-
"Username-Password-Authentication"
638+
UserData(email = email)
640639
).await()
641640

642641
val request = CreatePublicKeyCredentialRequest(
@@ -682,7 +681,7 @@ class DatabaseLoginFragment : Fragment() {
682681
try {
683682

684683
val challenge =
685-
authenticationApiClient.passkeyChallenge("Username-Password-Authentication")
684+
authenticationApiClient.passkeyChallenge()
686685
.await()
687686

688687
val request = GetPublicKeyCredentialOption(Gson().toJson(challenge.authParamsPublicKey))

0 commit comments

Comments
 (0)