Skip to content

Commit 1ffef71

Browse files
committed
Added support to pass organization while signing up with a passkey
1 parent c3c8219 commit 1ffef71

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -178,17 +178,20 @@ public class AuthenticationAPIClient @VisibleForTesting(otherwise = VisibleForTe
178178
* @param authSession the auth session received from the server as part of the public key challenge request.
179179
* @param authResponse the [PublicKeyCredentials] authentication response
180180
* @param realm the connection to use. If excluded, the application will use the default connection configured in the tenant
181+
* @param organization id of the organization to be associated with the user while signing in
181182
* @return a request to configure and start that will yield [Credentials]
182183
*/
183184
public fun signinWithPasskey(
184185
authSession: String,
185186
authResponse: PublicKeyCredentials,
186-
realm: String? = null
187+
realm: String? = null,
188+
organization: String? = null,
187189
): AuthenticationRequest {
188190
val params = ParameterBuilder.newBuilder().apply {
189191
setGrantType(ParameterBuilder.GRANT_TYPE_PASSKEY)
190192
set(AUTH_SESSION_KEY, authSession)
191193
realm?.let { setRealm(it) }
194+
organization?.let { set(ORGANIZATION_KEY,organization) }
192195
}.asDictionary()
193196

194197
return loginWithToken(params)
@@ -257,11 +260,13 @@ public class AuthenticationAPIClient @VisibleForTesting(otherwise = VisibleForTe
257260
*
258261
* @param userData user information of the client
259262
* @param realm the connection to use. If excluded, the application will use the default connection configured in the tenant
263+
* @param organization id of the organization to be associated with the user while signing up
260264
* @return a request to configure and start that will yield [PasskeyRegistrationChallenge]
261265
*/
262266
public fun signupWithPasskey(
263267
userData: UserData,
264-
realm: String? = null
268+
realm: String? = null,
269+
organization: String? = null
265270
): Request<PasskeyRegistrationChallenge, AuthenticationException> {
266271
val user = gson.toJsonTree(userData)
267272
val url = auth0.getDomainUrl().toHttpUrl().newBuilder()
@@ -272,6 +277,7 @@ public class AuthenticationAPIClient @VisibleForTesting(otherwise = VisibleForTe
272277
val params = ParameterBuilder.newBuilder().apply {
273278
setClientId(clientId)
274279
realm?.let { setRealm(it) }
280+
organization?.let { set(ORGANIZATION_KEY, it) }
275281
}.asDictionary()
276282

277283
val passkeyRegistrationChallengeAdapter: JsonAdapter<PasskeyRegistrationChallenge> =
@@ -304,7 +310,8 @@ public class AuthenticationAPIClient @VisibleForTesting(otherwise = VisibleForTe
304310
* @return a request to configure and start that will yield [PasskeyChallenge]
305311
*/
306312
public fun passkeyChallenge(
307-
realm: String? = null
313+
realm: String? = null,
314+
organization: String? = null
308315
): Request<PasskeyChallenge, AuthenticationException> {
309316
val url = auth0.getDomainUrl().toHttpUrl().newBuilder()
310317
.addPathSegment(PASSKEY_PATH)
@@ -314,6 +321,7 @@ public class AuthenticationAPIClient @VisibleForTesting(otherwise = VisibleForTe
314321
val parameters = ParameterBuilder.newBuilder().apply {
315322
setClientId(clientId)
316323
realm?.let { setRealm(it) }
324+
organization?.let { set(ORGANIZATION_KEY, organization) }
317325
}.asDictionary()
318326

319327
val passkeyChallengeAdapter: JsonAdapter<PasskeyChallenge> = GsonAdapter(
@@ -1054,7 +1062,7 @@ public class AuthenticationAPIClient @VisibleForTesting(otherwise = VisibleForTe
10541062
private const val RECOVERY_CODE_KEY = "recovery_code"
10551063
private const val SUBJECT_TOKEN_KEY = "subject_token"
10561064
private const val SUBJECT_TOKEN_TYPE_KEY = "subject_token_type"
1057-
private const val REQUESTED_TOKEN_TYPE_KEY = "requested_token_type"
1065+
private const val ORGANIZATION_KEY = "organization"
10581066
private const val USER_METADATA_KEY = "user_metadata"
10591067
private const val AUTH_SESSION_KEY = "auth_session"
10601068
private const val AUTH_RESPONSE_KEY = "authn_response"

auth0/src/test/java/com/auth0/android/authentication/AuthenticationAPIClientTest.kt

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,8 @@ public class AuthenticationAPIClientTest {
193193
val callback = MockAuthenticationCallback<Credentials>()
194194
val auth0 = auth0
195195
val client = AuthenticationAPIClient(auth0)
196-
client.signinWithPasskey("auth-session", mock<PublicKeyCredentials>(), MY_CONNECTION)
196+
client.signinWithPasskey("auth-session", mock<PublicKeyCredentials>(), MY_CONNECTION,
197+
"testOrganisation")
197198
.start(callback)
198199
ShadowLooper.idleMainLooper()
199200
assertThat(
@@ -216,6 +217,7 @@ public class AuthenticationAPIClientTest {
216217
)
217218
assertThat(body, Matchers.hasKey("authn_response"))
218219
assertThat(body, Matchers.hasEntry("auth_session", "auth-session"))
220+
assertThat(body, Matchers.hasEntry("organization", "testOrganisation"))
219221
}
220222

221223
@Test
@@ -225,7 +227,8 @@ public class AuthenticationAPIClientTest {
225227
val client = AuthenticationAPIClient(auth0)
226228
val registrationResponse = client.signupWithPasskey(
227229
mock(),
228-
MY_CONNECTION
230+
MY_CONNECTION,
231+
"testOrganization"
229232
)
230233
.execute()
231234
val request = mockAPI.takeRequest()
@@ -238,6 +241,7 @@ public class AuthenticationAPIClientTest {
238241
assertThat(request.path, Matchers.equalTo("/passkey/register"))
239242
assertThat(body, Matchers.hasEntry("client_id", CLIENT_ID))
240243
assertThat(body, Matchers.hasEntry("realm", MY_CONNECTION))
244+
assertThat(body, Matchers.hasEntry("organization", "testOrganization"))
241245
assertThat(body, Matchers.hasKey("user_profile"))
242246
assertThat(registrationResponse, Matchers.`is`(Matchers.notNullValue()))
243247
assertThat(registrationResponse.authSession, Matchers.comparesEqualTo(SESSION_ID))
@@ -248,7 +252,7 @@ public class AuthenticationAPIClientTest {
248252
mockAPI.willReturnSuccessfulPasskeyChallenge()
249253
val auth0 = auth0
250254
val client = AuthenticationAPIClient(auth0)
251-
val challengeResponse = client.passkeyChallenge(MY_CONNECTION)
255+
val challengeResponse = client.passkeyChallenge(MY_CONNECTION, "testOrganization")
252256
.execute()
253257
val request = mockAPI.takeRequest()
254258
assertThat(
@@ -260,6 +264,7 @@ public class AuthenticationAPIClientTest {
260264
assertThat(request.path, Matchers.equalTo("/passkey/challenge"))
261265
assertThat(body, Matchers.hasEntry("client_id", CLIENT_ID))
262266
assertThat(body, Matchers.hasEntry("realm", MY_CONNECTION))
267+
assertThat(body, Matchers.hasEntry("organization", "testOrganization"))
263268
assertThat(challengeResponse, Matchers.`is`(Matchers.notNullValue()))
264269
assertThat(challengeResponse.authSession, Matchers.comparesEqualTo(SESSION_ID))
265270

@@ -2749,7 +2754,6 @@ public class AuthenticationAPIClientTest {
27492754
private const val FIRST_NAME = "John"
27502755
private const val LAST_NAME = "Doe"
27512756
private const val COMPANY = "Auth0"
2752-
private const val OPENID = "openid"
27532757
private const val DEFAULT_LOCALE_IF_MISSING = "en_US"
27542758
}
27552759
}

0 commit comments

Comments
 (0)