verifyTwoFactorStepUp method
Future<AuthTwoFactorStepUpToken>
verifyTwoFactorStepUp(
- EngineContext ctx, {
- required String code,
Verifies TOTP for a sensitive action and sets a short-lived proof cookie.
Implementation
Future<AuthTwoFactorStepUpToken> verifyTwoFactorStepUp(
EngineContext ctx, {
required String code,
}) async {
final plugin = twoFactor;
if (plugin == null) {
throw AuthFlowException('two_factor_unavailable');
}
final session = await resolveSession(ctx);
final userId = session?.user.id.trim() ?? '';
if (userId.isEmpty) throw AuthFlowException('unauthorized');
final token = await plugin.verifyStepUp(
userId,
_twoFactorSessionBinding(ctx),
code,
);
ctx.response.cookies.add(
_buildManagedCookie(
ctx,
plugin.stepUpCookieName,
token.token,
expiresAt: token.expiresAt,
maxAge: plugin.stepUpTtl.inSeconds,
),
);
return token;
}