@@ -5,6 +5,9 @@ import android.util.Log
55import com.auth0.android.Auth0Exception
66import com.auth0.android.NetworkErrorException
77import com.auth0.android.provider.TokenValidationException
8+ import com.auth0.android.result.MfaFactor
9+ import com.auth0.android.result.MfaRequiredErrorPayload
10+ import com.auth0.android.result.MfaRequirements
811
912public class AuthenticationException : Auth0Exception {
1013 private var code: String? = null
@@ -147,6 +150,52 @@ public class AuthenticationException : Auth0Exception {
147150 public val isMultifactorEnrollRequired: Boolean
148151 get() = " a0.mfa_registration_required" == code || " unsupported_challenge_type" == code
149152
153+ /* *
154+ * Extracts the MFA required error payload when multifactor authentication is required.
155+ *
156+ * This property decodes the error values into a structured [MfaRequiredErrorPayload] object
157+ * containing the MFA token and enrollment requirements.
158+ *
159+ * ## Usage
160+ *
161+ * ```kotlin
162+ * if (error.isMultifactorRequired) {
163+ * val mfaPayload = error.mfaRequiredErrorPayload
164+ * val mfaToken = mfaPayload?.mfaToken
165+ * val enrollmentTypes = mfaPayload?.mfaRequirements?.enroll
166+ * }
167+ * ```
168+ *
169+ * @see isMultifactorRequired
170+ * @see MfaRequiredErrorPayload
171+ */
172+ public val mfaRequiredErrorPayload: MfaRequiredErrorPayload ?
173+ get() {
174+ val mfaToken = getValue(" mfa_token" ) as ? String ? : return null
175+ val errorCode = getCode()
176+ val errorDesc = getDescription()
177+ val requirements = getValue(" mfa_requirements" ) as ? Map <* , * >
178+
179+ @Suppress(" UNCHECKED_CAST" )
180+ val challengeList = (requirements?.get(" challenge" ) as ? List <Map <String , Any >>)?.map {
181+ MfaFactor (it[" type" ] as ? String ? : " " )
182+ }
183+
184+ @Suppress(" UNCHECKED_CAST" )
185+ val enrollList = (requirements?.get(" enroll" ) as ? List <Map <String , Any >>)?.map {
186+ MfaFactor (it[" type" ] as ? String ? : " " )
187+ }
188+
189+ return MfaRequiredErrorPayload (
190+ error = errorCode,
191+ errorDescription = errorDesc,
192+ mfaToken = mfaToken,
193+ mfaRequirements = if (challengeList != null || enrollList != null ) {
194+ MfaRequirements (enroll = enrollList, challenge = challengeList)
195+ } else null
196+ )
197+ }
198+
150199 // / When Bot Protection flags the request as suspicious
151200 public val isVerificationRequired: Boolean
152201 get() = " requires_verification" == code
0 commit comments