@@ -22,6 +22,8 @@ import com.auth0.android.result.Factors
2222import com.auth0.android.result.PasskeyAuthenticationMethod
2323import com.auth0.android.result.PasskeyEnrollmentChallenge
2424import com.auth0.android.result.PasskeyRegistrationChallenge
25+ import com.auth0.android.result.RecoveryCodeEnrollmentChallenge
26+ import com.auth0.android.result.TotpEnrollmentChallenge
2527
2628import com.google.gson.Gson
2729import okhttp3.HttpUrl
@@ -365,9 +367,9 @@ public class MyAccountAPIClient @VisibleForTesting(otherwise = VisibleForTesting
365367 *
366368 */
367369 @JvmOverloads
368- public fun updateAuthenticationMethodById (
370+ internal fun updateAuthenticationMethodById (
369371 authenticationMethodId : String ,
370- name : String? = null,
372+ authenticationMethodName : String? = null,
371373 preferredAuthenticationMethod : PhoneAuthenticationMethodType ? = null
372374 ): Request <AuthenticationMethod , MyAccountException > {
373375 val url = getDomainUrlBuilder()
@@ -376,7 +378,7 @@ public class MyAccountAPIClient @VisibleForTesting(otherwise = VisibleForTesting
376378 .build()
377379
378380 val params = ParameterBuilder .newBuilder().apply {
379- name ?.let { set(AUTHENTICATION_METHOD_NAME , it) }
381+ authenticationMethodName ?.let { set(AUTHENTICATION_METHOD_NAME , it) }
380382 preferredAuthenticationMethod?.let {
381383 set(
382384 PREFERRED_AUTHENTICATION_METHOD ,
@@ -441,7 +443,7 @@ public class MyAccountAPIClient @VisibleForTesting(otherwise = VisibleForTesting
441443 * Gets the list of factors available for the user to enroll.
442444 *
443445 * ## Scopes Required
444- * `read:me`
446+ * `read:me:factors `
445447 *
446448 * ## Usage
447449 *
@@ -560,7 +562,7 @@ public class MyAccountAPIClient @VisibleForTesting(otherwise = VisibleForTesting
560562 * val apiClient = MyAccountAPIClient(auth0, accessToken)
561563 *
562564 * apiClient.enrollTotp()
563- * .start(object : Callback<EnrollmentChallenge , MyAccountException> {
565+ * .start(object : Callback<TotpEnrollmentChallenge , MyAccountException> {
564566 * override fun onSuccess(result: EnrollmentChallenge) {
565567 * // The result will be a TotpEnrollmentChallenge with a barcode_uri
566568 * Log.d("MyApp", "Enrollment started for TOTP.")
@@ -570,9 +572,13 @@ public class MyAccountAPIClient @VisibleForTesting(otherwise = VisibleForTesting
570572 * ```
571573 * @return a request that will yield an enrollment challenge.
572574 */
573- public fun enrollTotp (): Request <EnrollmentChallenge , MyAccountException > {
575+ public fun enrollTotp (): Request <TotpEnrollmentChallenge , MyAccountException > {
574576 val params = ParameterBuilder .newBuilder().set(TYPE_KEY , " totp" ).asDictionary()
575- return buildEnrollmentRequest(params)
577+ val url = getDomainUrlBuilder().addPathSegment(AUTHENTICATION_METHODS ).build()
578+ val adapter = GsonAdapter (TotpEnrollmentChallenge ::class .java, gson)
579+ return factory.post(url.toString(), adapter)
580+ .addParameters(params)
581+ .addHeader(AUTHORIZATION_KEY , " Bearer $accessToken " )
576582 }
577583
578584 /* *
@@ -588,7 +594,7 @@ public class MyAccountAPIClient @VisibleForTesting(otherwise = VisibleForTesting
588594 * val apiClient = MyAccountAPIClient(auth0, accessToken)
589595 *
590596 * apiClient.enrollPushNotification()
591- * .start(object : Callback<EnrollmentChallenge , MyAccountException> {
597+ * .start(object : Callback<TotpEnrollmentChallenge , MyAccountException> {
592598 * override fun onSuccess(result: EnrollmentChallenge) {
593599 * // The result will be a TotpEnrollmentChallenge containing a barcode_uri
594600 * Log.d("MyApp", "Enrollment started for Push Notification.")
@@ -598,9 +604,14 @@ public class MyAccountAPIClient @VisibleForTesting(otherwise = VisibleForTesting
598604 * ```
599605 * @return a request that will yield an enrollment challenge.
600606 */
601- public fun enrollPushNotification (): Request <EnrollmentChallenge , MyAccountException > {
607+ public fun enrollPushNotification (): Request <TotpEnrollmentChallenge , MyAccountException > {
602608 val params = ParameterBuilder .newBuilder().set(TYPE_KEY , " push-notification" ).asDictionary()
603- return buildEnrollmentRequest(params)
609+ val url = getDomainUrlBuilder().addPathSegment(AUTHENTICATION_METHODS ).build()
610+ // The response structure for push notification challenge is the same as TOTP (contains barcode_uri)
611+ val adapter = GsonAdapter (TotpEnrollmentChallenge ::class .java, gson)
612+ return factory.post(url.toString(), adapter)
613+ .addParameters(params)
614+ .addHeader(AUTHORIZATION_KEY , " Bearer $accessToken " )
604615 }
605616
606617 /* *
@@ -616,7 +627,7 @@ public class MyAccountAPIClient @VisibleForTesting(otherwise = VisibleForTesting
616627 * val apiClient = MyAccountAPIClient(auth0, accessToken)
617628 *
618629 * apiClient.enrollRecoveryCode()
619- * .start(object : Callback<EnrollmentChallenge , MyAccountException> {
630+ * .start(object : Callback<RecoveryCodeEnrollmentChallenge , MyAccountException> {
620631 * override fun onSuccess(result: EnrollmentChallenge) {
621632 * // The result will be a RecoveryCodeEnrollmentChallenge containing the code
622633 * Log.d("MyApp", "Recovery Code enrollment started.")
@@ -626,9 +637,13 @@ public class MyAccountAPIClient @VisibleForTesting(otherwise = VisibleForTesting
626637 * ```
627638 * @return a request that will yield an enrollment challenge containing the recovery code.
628639 */
629- public fun enrollRecoveryCode (): Request <EnrollmentChallenge , MyAccountException > {
640+ public fun enrollRecoveryCode (): Request <RecoveryCodeEnrollmentChallenge , MyAccountException > {
630641 val params = ParameterBuilder .newBuilder().set(TYPE_KEY , " recovery-code" ).asDictionary()
631- return buildEnrollmentRequest(params)
642+ val url = getDomainUrlBuilder().addPathSegment(AUTHENTICATION_METHODS ).build()
643+ val adapter = GsonAdapter (RecoveryCodeEnrollmentChallenge ::class .java, gson)
644+ return factory.post(url.toString(), adapter)
645+ .addParameters(params)
646+ .addHeader(AUTHORIZATION_KEY , " Bearer $accessToken " )
632647 }
633648
634649 /* *
@@ -770,14 +785,11 @@ public class MyAccountAPIClient @VisibleForTesting(otherwise = VisibleForTesting
770785 return buildEnrollmentRequest(params)
771786 }
772787
773- private fun buildEnrollmentRequest (params : Map <String , Any >): Request <EnrollmentChallenge , MyAccountException > {
788+ private fun buildEnrollmentRequest (params : Map <String , String >): Request <EnrollmentChallenge , MyAccountException > {
774789 val url = getDomainUrlBuilder().addPathSegment(AUTHENTICATION_METHODS ).build()
775- val request =
776- factory.post(url.toString(), GsonAdapter (EnrollmentChallenge ::class .java, gson))
777- for ((key, value) in params) {
778- request.addParameter(key, value)
779- }
780- return request.addHeader(AUTHORIZATION_KEY , " Bearer $accessToken " )
790+ return factory.post(url.toString(), GsonAdapter (EnrollmentChallenge ::class .java, gson))
791+ .addParameters(params)
792+ .addHeader(AUTHORIZATION_KEY , " Bearer $accessToken " )
781793 }
782794
783795 private fun getDomainUrlBuilder (): HttpUrl .Builder {
0 commit comments