redeemOtp static method Null safety
Redeems an OTP for a grant code.
Returns a promise that resolves to an AuthenticateResponse on success or an OtpChallengeResponse on failure to authenticate with the provided OTP code. Use the url provided in OtpChallengeResponse for retry.
url
The authentication URL of the current transaction.
otp
The OTP to redeem..
Returns a AuthenticateResponse or OtpChallengeResponse or throws an Exception
Implementation
static Future<RedeemOtpResponse> redeemOtp(String url, String otp) async {
final Map<String, dynamic>? redeemOtpResponse =
await _channel.invokeMapMethod('redeemOtp', {
'url': url,
'otp': otp,
});
try {
if (redeemOtpResponse != null) {
if (redeemOtpResponse.containsKey('redirectUrl')) {
return RedeemOtpResponse.success(AuthenticateResponse(
redirectUrl: redeemOtpResponse["redirectUrl"],
message: redeemOtpResponse["message"],
passkeyBindingToken: redeemOtpResponse["passkeyBindingToken"]
));
} else if (redeemOtpResponse.containsKey('url')) {
return RedeemOtpResponse.failedOtp(OtpChallengeResponse(
url: redeemOtpResponse['url'],
));
}
}
throw Exception(
'Invalid response from redeemOtp: Neither AuthenticateResponse nor OtpChallengeResponse found.');
} on Exception {
rethrow;
}
}