Return the passkey session id in the redirect data

This commit is contained in:
Manav Rathi
2024-06-13 16:18:01 +05:30
parent d34bcffafd
commit f2928c8ab8
2 changed files with 8 additions and 1 deletions

View File

@@ -118,6 +118,7 @@ const Page = () => {
setRedirectURLWithData(
await redirectURLWithPasskeyAuthentication(
redirectURL,
passkeySessionID,
authorizationResponse,
),
);

View File

@@ -552,15 +552,21 @@ const authenticatorAssertionResponse = (credential: Credential) => {
* @param redirectURL The base URL to redirect to. Provided by the calling app
* that initiated the passkey authentication.
*
* @param passkeySessionID The passkeySessionID that was provided by the calling
* app that initiated the passkey authentication. It is returned back in the
* response so that the calling app has a way to ensure that this is indeed a
* redirect for the session that they initiated and are waiting for.
*
* @param twoFactorAuthorizationResponse The result of
* {@link finishPasskeyAuthentication} returned by the backend.
*/
export const redirectURLWithPasskeyAuthentication = async (
redirectURL: URL,
passkeySessionID: string,
twoFactorAuthorizationResponse: TwoFactorAuthorizationResponse,
) => {
const encodedResponse = await toB64URLSafeNoPaddingString(
JSON.stringify(twoFactorAuthorizationResponse),
JSON.stringify({ ...twoFactorAuthorizationResponse, passkeySessionID }),
);
redirectURL.searchParams.set("response", encodedResponse);
return redirectURL;