Skip to content

Commit 28f059c

Browse files
committed
Added the initial set of api for passkey /authentication methods management
1 parent 7b519d9 commit 28f059c

2 files changed

Lines changed: 91 additions & 4 deletions

File tree

auth0/src/main/java/com/auth0/android/myaccount/MyAccountAPIClient.kt

Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.auth0.android.myaccount
22

33
import androidx.annotation.VisibleForTesting
4+
import androidx.browser.customtabs.CustomTabsService.Result
45
import com.auth0.android.Auth0
56
import com.auth0.android.Auth0Exception
67
import com.auth0.android.NetworkErrorException
@@ -14,6 +15,7 @@ import com.auth0.android.request.internal.GsonAdapter.Companion.forMap
1415
import com.auth0.android.request.internal.GsonProvider
1516
import com.auth0.android.request.internal.RequestFactory
1617
import com.auth0.android.request.internal.ResponseUtils.isNetworkError
18+
import com.auth0.android.result.AuthenticationMethod
1719
import com.auth0.android.result.PasskeyAuthenticationMethod
1820
import com.auth0.android.result.PasskeyEnrollmentChallenge
1921
import com.auth0.android.result.PasskeyRegistrationChallenge
@@ -244,7 +246,7 @@ public class MyAccountAPIClient @VisibleForTesting(otherwise = VisibleForTesting
244246
"type" to "public-key",
245247
"response" to mapOf(
246248
"clientDataJSON" to credentials.response.clientDataJSON,
247-
"attestationObject" to credentials.response.attestationObject
249+
"attestationObject" to credentials.response.attestationObject,
248250
)
249251
)
250252

@@ -266,7 +268,56 @@ public class MyAccountAPIClient @VisibleForTesting(otherwise = VisibleForTesting
266268

267269

268270
/**
269-
* Deletes an existing authentication method.
271+
* Retrieves a single authentication method belonging to the user.
272+
*
273+
* ## Availability
274+
*
275+
* This feature is currently available in
276+
* [Early Access](https://auth0.com/docs/troubleshoot/product-lifecycle/product-release-stages#early-access).
277+
* Please reach out to Auth0 support to get it enabled for your tenant.
278+
*
279+
*
280+
* ## Usage
281+
*
282+
* ```kotlin
283+
* val auth0 = Auth0.getInstance("YOUR_CLIENT_ID", "YOUR_DOMAIN")
284+
* val apiClient = MyAccountAPIClient(auth0, accessToken)
285+
*
286+
*
287+
* apiClient.getAuthenticationMethod(authenticationMethodId, )
288+
* .start(object : Callback<AuthenticationMethod, MyAccountException> {
289+
* override fun onSuccess(result: AuthenticationMethod) {
290+
* Log.d("MyApp", "Authentication method $result")
291+
* }
292+
*
293+
* override fun onFailure(error: MyAccountException) {
294+
* Log.e("MyApp", "Failed with: ${error.message}")
295+
* }
296+
* })
297+
* ```
298+
*
299+
* @param authenticationMethodId Id of the authentication method to be retrieved
300+
*
301+
*/
302+
public fun getAuthenticationMethod(authenticationMethodId: String): Result<AuthenticationMethod, MyAccountException> {
303+
val url =
304+
getDomainUrlBuilder()
305+
.addPathSegment(AUTHENTICATION_METHODS)
306+
.addPathSegment(authenticationMethodId)
307+
.build()
308+
309+
val request = factory.get(
310+
url.toString(),
311+
GsonAdapter(AuthenticationMethod::class.java)
312+
)
313+
.addHeader(AUTHORIZATION_KEY, "Bearer $accessToken")
314+
315+
return request
316+
}
317+
318+
319+
/**
320+
* Deletes an existing authentication method belonging to the user.
270321
*
271322
* ## Availability
272323
*
@@ -284,7 +335,7 @@ public class MyAccountAPIClient @VisibleForTesting(otherwise = VisibleForTesting
284335
* val apiClient = MyAccountAPIClient(auth0, accessToken)
285336
*
286337
*
287-
* apiClient.delete(authenticationMethodId, )
338+
* apiClient.deleteAuthenticationMethod(authenticationMethodId, )
288339
* .start(object : Callback<Void, MyAccountException> {
289340
* override fun onSuccess(result: Void) {
290341
* Log.d("MyApp", "Authentication method deleted")
@@ -299,7 +350,7 @@ public class MyAccountAPIClient @VisibleForTesting(otherwise = VisibleForTesting
299350
* @param authenticationMethodId Id of the authentication method to be deleted
300351
*
301352
*/
302-
public fun delete(
353+
public fun deleteAuthenticationMethod(
303354
authenticationMethodId: String
304355
): Request<Void, MyAccountException> {
305356
val url =
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.auth0.android.result
2+
3+
4+
import com.google.gson.annotations.SerializedName
5+
6+
/**
7+
* An Authentication Method
8+
*/
9+
public data class AuthenticationMethod(
10+
@SerializedName("created_at")
11+
val createdAt: String,
12+
@SerializedName("credential_backed_up")
13+
val credentialBackedUp: Boolean?,
14+
@SerializedName("credential_device_type")
15+
val credentialDeviceType: String?,
16+
@SerializedName("id")
17+
val id: String,
18+
@SerializedName("identity_user_id")
19+
val identityUserId: String,
20+
@SerializedName("key_id")
21+
val keyId: String?,
22+
@SerializedName("last_password_reset")
23+
val lastPasswordReset: String,
24+
@SerializedName("public_key")
25+
val publicKey: String?,
26+
@SerializedName("transports")
27+
val transports: List<String>?,
28+
@SerializedName("type")
29+
val type: String,
30+
@SerializedName("usage")
31+
val usage: String,
32+
@SerializedName("user_agent")
33+
val userAgent: String?,
34+
@SerializedName("user_handle")
35+
val userHandle: String?
36+
)

0 commit comments

Comments
 (0)