11package com.auth0.android.myaccount
22
33import androidx.annotation.VisibleForTesting
4- import androidx.browser.customtabs.CustomTabsService.Result
54import com.auth0.android.Auth0
65import com.auth0.android.Auth0Exception
76import com.auth0.android.NetworkErrorException
@@ -16,6 +15,7 @@ import com.auth0.android.request.internal.GsonProvider
1615import com.auth0.android.request.internal.RequestFactory
1716import com.auth0.android.request.internal.ResponseUtils.isNetworkError
1817import com.auth0.android.result.AuthenticationMethod
18+ import com.auth0.android.result.AuthenticationMethods
1919import com.auth0.android.result.PasskeyAuthenticationMethod
2020import com.auth0.android.result.PasskeyEnrollmentChallenge
2121import 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 > {
0 commit comments