mirror of
https://github.com/zitadel/zitadel.git
synced 2025-12-12 10:15:04 +00:00
passkey fix
This commit is contained in:
@@ -45,7 +45,7 @@ export async function PUT(request: NextRequest) {
|
|||||||
const body = await request.json();
|
const body = await request.json();
|
||||||
|
|
||||||
if (body) {
|
if (body) {
|
||||||
const { loginName, password, passkey, authRequestId } = body;
|
const { loginName, password, webAuthN, authRequestId } = body;
|
||||||
const challenges: RequestChallenges = body.challenges;
|
const challenges: RequestChallenges = body.challenges;
|
||||||
|
|
||||||
const recentPromise: Promise<SessionCookie> = loginName
|
const recentPromise: Promise<SessionCookie> = loginName
|
||||||
@@ -64,12 +64,13 @@ export async function PUT(request: NextRequest) {
|
|||||||
|
|
||||||
return recentPromise
|
return recentPromise
|
||||||
.then((recent) => {
|
.then((recent) => {
|
||||||
|
console.log("setsession", webAuthN);
|
||||||
return setSessionAndUpdateCookie(
|
return setSessionAndUpdateCookie(
|
||||||
recent.id,
|
recent.id,
|
||||||
recent.token,
|
recent.token,
|
||||||
recent.loginName,
|
recent.loginName,
|
||||||
password,
|
password,
|
||||||
passkey,
|
webAuthN,
|
||||||
challenges,
|
challenges,
|
||||||
authRequestId
|
authRequestId
|
||||||
).then((session) => {
|
).then((session) => {
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ export default function LoginPasskey({
|
|||||||
.then((response) => {
|
.then((response) => {
|
||||||
console.log(response);
|
console.log(response);
|
||||||
const pK =
|
const pK =
|
||||||
response.challenges.passkey.publicKeyCredentialRequestOptions
|
response.challenges.webAuthN.publicKeyCredentialRequestOptions
|
||||||
.publicKey;
|
.publicKey;
|
||||||
if (pK) {
|
if (pK) {
|
||||||
submitLoginAndContinue(pK)
|
submitLoginAndContinue(pK)
|
||||||
@@ -68,7 +68,7 @@ export default function LoginPasskey({
|
|||||||
challenges: {
|
challenges: {
|
||||||
webAuthN: {
|
webAuthN: {
|
||||||
domain: "",
|
domain: "",
|
||||||
userVerificationRequirement: 2,
|
userVerificationRequirement: 1,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
authRequestId,
|
authRequestId,
|
||||||
@@ -85,6 +85,7 @@ export default function LoginPasskey({
|
|||||||
|
|
||||||
async function submitLogin(data: any) {
|
async function submitLogin(data: any) {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
|
console.log(data);
|
||||||
const res = await fetch("/api/session", {
|
const res = await fetch("/api/session", {
|
||||||
method: "PUT",
|
method: "PUT",
|
||||||
headers: {
|
headers: {
|
||||||
@@ -92,7 +93,7 @@ export default function LoginPasskey({
|
|||||||
},
|
},
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
loginName,
|
loginName,
|
||||||
passkey: data,
|
webAuthN: { credentialAssertionData: data },
|
||||||
authRequestId,
|
authRequestId,
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
@@ -127,18 +128,18 @@ export default function LoginPasskey({
|
|||||||
})
|
})
|
||||||
.then((assertedCredential: any) => {
|
.then((assertedCredential: any) => {
|
||||||
if (assertedCredential) {
|
if (assertedCredential) {
|
||||||
let authData = new Uint8Array(
|
const authData = new Uint8Array(
|
||||||
assertedCredential.response.authenticatorData
|
assertedCredential.response.authenticatorData
|
||||||
);
|
);
|
||||||
let clientDataJSON = new Uint8Array(
|
const clientDataJSON = new Uint8Array(
|
||||||
assertedCredential.response.clientDataJSON
|
assertedCredential.response.clientDataJSON
|
||||||
);
|
);
|
||||||
let rawId = new Uint8Array(assertedCredential.rawId);
|
const rawId = new Uint8Array(assertedCredential.rawId);
|
||||||
let sig = new Uint8Array(assertedCredential.response.signature);
|
const sig = new Uint8Array(assertedCredential.response.signature);
|
||||||
let userHandle = new Uint8Array(
|
const userHandle = new Uint8Array(
|
||||||
assertedCredential.response.userHandle
|
assertedCredential.response.userHandle
|
||||||
);
|
);
|
||||||
let data = JSON.stringify({
|
const data = JSON.stringify({
|
||||||
id: assertedCredential.id,
|
id: assertedCredential.id,
|
||||||
rawId: coerceToBase64Url(rawId, "rawId"),
|
rawId: coerceToBase64Url(rawId, "rawId"),
|
||||||
type: assertedCredential.type,
|
type: assertedCredential.type,
|
||||||
|
|||||||
@@ -58,17 +58,16 @@ export async function setSessionAndUpdateCookie(
|
|||||||
sessionToken: string,
|
sessionToken: string,
|
||||||
loginName: string,
|
loginName: string,
|
||||||
password: string | undefined,
|
password: string | undefined,
|
||||||
passkey: { credentialAssertionData: any } | undefined,
|
webAuthN: { credentialAssertionData: any } | undefined,
|
||||||
challenges: RequestChallenges | undefined,
|
challenges: RequestChallenges | undefined,
|
||||||
authRequestId: string | undefined
|
authRequestId: string | undefined
|
||||||
): Promise<SessionWithChallenges> {
|
): Promise<SessionWithChallenges> {
|
||||||
console.log(password, passkey, challenges);
|
|
||||||
return setSession(
|
return setSession(
|
||||||
server,
|
server,
|
||||||
sessionId,
|
sessionId,
|
||||||
sessionToken,
|
sessionToken,
|
||||||
password,
|
password,
|
||||||
passkey,
|
webAuthN,
|
||||||
challenges
|
challenges
|
||||||
).then((updatedSession) => {
|
).then((updatedSession) => {
|
||||||
if (updatedSession) {
|
if (updatedSession) {
|
||||||
@@ -83,9 +82,14 @@ export async function setSessionAndUpdateCookie(
|
|||||||
sessionCookie.authRequestId = authRequestId;
|
sessionCookie.authRequestId = authRequestId;
|
||||||
}
|
}
|
||||||
|
|
||||||
return getSession(server, sessionCookie.id, sessionCookie.token).then(
|
return new Promise((resolve) => setTimeout(resolve, 1000)).then(() =>
|
||||||
|
// TODO: remove
|
||||||
|
getSession(server, sessionCookie.id, sessionCookie.token).then(
|
||||||
(response) => {
|
(response) => {
|
||||||
if (response?.session && response.session.factors?.user?.loginName) {
|
if (
|
||||||
|
response?.session &&
|
||||||
|
response.session.factors?.user?.loginName
|
||||||
|
) {
|
||||||
const { session } = response;
|
const { session } = response;
|
||||||
const newCookie: SessionCookie = {
|
const newCookie: SessionCookie = {
|
||||||
id: sessionCookie.id,
|
id: sessionCookie.id,
|
||||||
@@ -98,13 +102,16 @@ export async function setSessionAndUpdateCookie(
|
|||||||
newCookie.authRequestId = sessionCookie.authRequestId;
|
newCookie.authRequestId = sessionCookie.authRequestId;
|
||||||
}
|
}
|
||||||
|
|
||||||
return updateSessionCookie(sessionCookie.id, newCookie).then(() => {
|
return updateSessionCookie(sessionCookie.id, newCookie).then(
|
||||||
|
() => {
|
||||||
return { challenges: updatedSession.challenges, ...session };
|
return { challenges: updatedSession.challenges, ...session };
|
||||||
});
|
}
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
throw "could not get session or session does not have loginName";
|
throw "could not get session or session does not have loginName";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
)
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
throw "Session not be set";
|
throw "Session not be set";
|
||||||
|
|||||||
Reference in New Issue
Block a user