Skip to content

Commit 2dd8661

Browse files
committed
Added the remaining end points
1 parent 7413b06 commit 2dd8661

File tree

2 files changed

+121
-4
lines changed

2 files changed

+121
-4
lines changed

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

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

33
import androidx.annotation.VisibleForTesting
4-
import androidx.browser.customtabs.CustomTabsService.Result
54
import com.auth0.android.Auth0
65
import com.auth0.android.Auth0Exception
76
import com.auth0.android.NetworkErrorException
@@ -16,6 +15,7 @@ import com.auth0.android.request.internal.GsonProvider
1615
import com.auth0.android.request.internal.RequestFactory
1716
import com.auth0.android.request.internal.ResponseUtils.isNetworkError
1817
import com.auth0.android.result.AuthenticationMethod
18+
import com.auth0.android.result.AuthenticationMethods
1919
import com.auth0.android.result.PasskeyAuthenticationMethod
2020
import com.auth0.android.result.PasskeyEnrollmentChallenge
2121
import com.auth0.android.result.PasskeyRegistrationChallenge
@@ -267,6 +267,52 @@ public class MyAccountAPIClient @VisibleForTesting(otherwise = VisibleForTesting
267267
}
268268

269269

270+
/**
271+
* Retrieves a detailed list of authentication methods 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.getAuthenticationMethods()
288+
* .start(object : Callback<AuthenticationMethods, MyAccountException> {
289+
* override fun onSuccess(result: AuthenticationMethods) {
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+
*/
300+
public fun getAuthenticationMethods(): Request<AuthenticationMethods, MyAccountException> {
301+
val url =
302+
getDomainUrlBuilder()
303+
.addPathSegment(AUTHENTICATION_METHODS)
304+
.build()
305+
306+
val request = factory.get(
307+
url.toString(),
308+
GsonAdapter(AuthenticationMethods::class.java)
309+
)
310+
.addHeader(AUTHORIZATION_KEY, "Bearer $accessToken")
311+
312+
return request
313+
}
314+
315+
270316
/**
271317
* Retrieves a single authentication method belonging to the user.
272318
*
@@ -284,7 +330,7 @@ public class MyAccountAPIClient @VisibleForTesting(otherwise = VisibleForTesting
284330
* val apiClient = MyAccountAPIClient(auth0, accessToken)
285331
*
286332
*
287-
* apiClient.getAuthenticationMethod(authenticationMethodId, )
333+
* apiClient.getAuthenticationMethodById(authenticationMethodId, )
288334
* .start(object : Callback<AuthenticationMethod, MyAccountException> {
289335
* override fun onSuccess(result: AuthenticationMethod) {
290336
* Log.d("MyApp", "Authentication method $result")
@@ -299,7 +345,7 @@ public class MyAccountAPIClient @VisibleForTesting(otherwise = VisibleForTesting
299345
* @param authenticationMethodId Id of the authentication method to be retrieved
300346
*
301347
*/
302-
public fun getAuthenticationMethod(authenticationMethodId: String): Result<AuthenticationMethod, MyAccountException> {
348+
public fun getAuthenticationMethodById(authenticationMethodId: String): Request<AuthenticationMethod, MyAccountException> {
303349
val url =
304350
getDomainUrlBuilder()
305351
.addPathSegment(AUTHENTICATION_METHODS)
@@ -315,6 +361,66 @@ public class MyAccountAPIClient @VisibleForTesting(otherwise = VisibleForTesting
315361
return request
316362
}
317363

364+
/**
365+
* Updates a single authentication method belonging to the user.
366+
*
367+
* ## Availability
368+
*
369+
* This feature is currently available in
370+
* [Early Access](https://auth0.com/docs/troubleshoot/product-lifecycle/product-release-stages#early-access).
371+
* Please reach out to Auth0 support to get it enabled for your tenant.
372+
*
373+
*
374+
* ## Usage
375+
*
376+
* ```kotlin
377+
* val auth0 = Auth0.getInstance("YOUR_CLIENT_ID", "YOUR_DOMAIN")
378+
* val apiClient = MyAccountAPIClient(auth0, accessToken)
379+
*
380+
*
381+
* apiClient.updateAuthenticationMethodById(authenticationMethodId,preferredAuthenticationMethod, authenticationMethodName)
382+
* .start(object : Callback<AuthenticationMethod, MyAccountException> {
383+
* override fun onSuccess(result: AuthenticationMethod) {
384+
* Log.d("MyApp", "Authentication method $result")
385+
* }
386+
*
387+
* override fun onFailure(error: MyAccountException) {
388+
* Log.e("MyApp", "Failed with: ${error.message}")
389+
* }
390+
* })
391+
* ```
392+
*
393+
* @param authenticationMethodId Id of the authentication method to be retrieved
394+
* @param authenticationMethodName The friendly name of the authentication method
395+
* @param preferredAuthenticationMethod The preferred authentication method for the user. (for phone authenticators)
396+
*
397+
*/
398+
public fun updateAuthenticationMethodById(
399+
authenticationMethodId: String,
400+
preferredAuthenticationMethod: String,
401+
authenticationMethodName: String
402+
): Request<AuthenticationMethod, MyAccountException> {
403+
val url =
404+
getDomainUrlBuilder()
405+
.addPathSegment(AUTHENTICATION_METHODS)
406+
.addPathSegment(authenticationMethodId)
407+
.build()
408+
409+
val params = ParameterBuilder.newBuilder().apply {
410+
set(PREFERRED_AUTHENTICATION_METHOD, preferredAuthenticationMethod)
411+
set(AUTHENTICATION_METHOD_NAME, authenticationMethodName)
412+
}.asDictionary()
413+
414+
val request = factory.patch(
415+
url.toString(),
416+
GsonAdapter(AuthenticationMethod::class.java)
417+
)
418+
.addHeader(AUTHORIZATION_KEY, "Bearer $accessToken")
419+
.addParameters(params)
420+
421+
return request
422+
}
423+
318424

319425
/**
320426
* Deletes an existing authentication method belonging to the user.
@@ -385,6 +491,8 @@ public class MyAccountAPIClient @VisibleForTesting(otherwise = VisibleForTesting
385491
private const val LOCATION_KEY = "location"
386492
private const val AUTH_SESSION_KEY = "auth_session"
387493
private const val AUTHN_RESPONSE_KEY = "authn_response"
494+
private const val PREFERRED_AUTHENTICATION_METHOD = "preferred_authentication_method"
495+
private const val AUTHENTICATION_METHOD_NAME = "name"
388496
private fun createErrorAdapter(): ErrorAdapter<MyAccountException> {
389497
val mapAdapter = forMap(GsonProvider.gson)
390498
return object : ErrorAdapter<MyAccountException> {

auth0/src/main/java/com/auth0/android/result/AuthenticationMethod.kt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,18 @@ public data class AuthenticationMethod(
2828
@SerializedName("type")
2929
val type: String,
3030
@SerializedName("usage")
31-
val usage: String,
31+
val usage: List<String>,
3232
@SerializedName("user_agent")
3333
val userAgent: String?,
3434
@SerializedName("user_handle")
3535
val userHandle: String?
36+
)
37+
38+
39+
/**
40+
* List of Authentication Methods
41+
*/
42+
public data class AuthenticationMethods(
43+
@SerializedName("authentication_methods")
44+
val authenticationMethods: List<AuthenticationMethod>
3645
)

0 commit comments

Comments
 (0)