ripe-megabyte-17595
08/30/2023, 12:19 PMconst response = await ory.updateLoginFlow({
flow: flow.id,
updateLoginFlowBody: {
csrf_token: csrfToken,
method: SessionAuthenticationMethodMethodEnum.Password,
...values,
},
});
try {
await ory.toSession();
} catch (err: any) {
if (err.response.data.error.id === 'session_aal2_required') {
console.log(err);
debugger;
router.push(
`/login?aal=aal2${
search?.has('return_to') ? `&return_to=${search.get('return_to')}` : ''
}`
);
return;
}
}
Once the code is entered I call updateLoginFlow with the same flow id as the above but it responses with
“valid session already exists and thus can’t complete login”
const response = await ory.updateLoginFlow({
flow: flow.id,
updateLoginFlowBody: {
csrf_token: csrfToken,
method: SessionAuthenticationMethodMethodEnum.Totp,
totp_code,
},
});
Anyone have insights into what I’m doing incorrectly. A note that the account I’m testing has totp active as the toSession call is returne the session_aal2_required
magnificent-energy-493
session_already_available
error in the API Reference. You might want to check the session status before attempting to update the login flow.
2. Required Level of Authentication: When initializing the second authentication factor, the user must already have a valid session cookie. The /sessions/whoami
endpoint returns an error with the session_aal2_required
ID if the user is required to complete a second factor. This is mentioned in the Advanced Integration documentation.
3. TOTP Configuration: Ensure that TOTP has been correctly enabled for the user’s account. The user must enable TOTP in their own account by pairing their account with a TOTP app. This is detailed in the TOTP Authentication documentation.
If you’re still encountering issues, you might want to refer to the Cypress tests used in Ory Identities (Ory Kratos) for TOTP implementation as a reference.ripe-megabyte-17595
08/30/2023, 2:16 PMconst response = await ory.updateLoginFlow({
flow: flow.id,
updateLoginFlowBody: {
csrf_token: csrfToken,
method: SessionAuthenticationMethodMethodEnum.Totp,
totp_code,
},
});
full-diamond-56778
08/31/2023, 7:52 AMrefresh=true
query parameter as someone needs to be authenticated by aal2
/login?aal=aal2&refresh=true
and then the ory can "handle" the new flow for the valid session in cookiesripe-megabyte-17595
08/31/2023, 9:20 AM