put session by id

This commit is contained in:
peintnermax
2024-04-03 16:34:45 +02:00
parent 87a2344b56
commit 5e4c2eebcc
3 changed files with 31 additions and 6 deletions

View File

@@ -66,13 +66,14 @@ export default async function Page({
{!sessionFactors && <div className="py-4"></div>} {!sessionFactors && <div className="py-4"></div>}
{!loginName && ( {!(loginName || sessionId) && (
<Alert>Provide your active session as loginName param</Alert> <Alert>Provide your active session as loginName param</Alert>
)} )}
{loginName && ( {(loginName || sessionId) && (
<LoginPasskey <LoginPasskey
loginName={loginName} loginName={loginName}
sessionId={sessionId}
authRequestId={authRequestId} authRequestId={authRequestId}
altPassword={altPassword === "true"} altPassword={altPassword === "true"}
organization={organization} organization={organization}

View File

@@ -63,10 +63,21 @@ export async function PUT(request: NextRequest) {
const body = await request.json(); const body = await request.json();
if (body) { if (body) {
const { loginName, organization, password, webAuthN, authRequestId } = body; const {
loginName,
sessionId,
organization,
password,
webAuthN,
authRequestId,
} = body;
const challenges: RequestChallenges = body.challenges; const challenges: RequestChallenges = body.challenges;
const recentPromise: Promise<SessionCookie> = loginName const recentPromise: Promise<SessionCookie> = sessionId
? getSessionCookieById(sessionId).catch((error) => {
return Promise.reject(error);
})
: loginName
? getSessionCookieByLoginName(loginName, organization).catch((error) => { ? getSessionCookieByLoginName(loginName, organization).catch((error) => {
return Promise.reject(error); return Promise.reject(error);
}) })

View File

@@ -7,8 +7,10 @@ import { Button, ButtonVariants } from "./Button";
import Alert from "./Alert"; import Alert from "./Alert";
import { Spinner } from "./Spinner"; import { Spinner } from "./Spinner";
// either loginName or sessionId must be provided
type Props = { type Props = {
loginName: string; loginName?: string;
sessionId?: string;
authRequestId?: string; authRequestId?: string;
altPassword: boolean; altPassword: boolean;
organization?: string; organization?: string;
@@ -16,6 +18,7 @@ type Props = {
export default function LoginPasskey({ export default function LoginPasskey({
loginName, loginName,
sessionId,
authRequestId, authRequestId,
altPassword, altPassword,
organization, organization,
@@ -66,6 +69,7 @@ export default function LoginPasskey({
}, },
body: JSON.stringify({ body: JSON.stringify({
loginName, loginName,
sessionId,
organization, organization,
challenges: { challenges: {
webAuthN: { webAuthN: {
@@ -94,6 +98,7 @@ export default function LoginPasskey({
}, },
body: JSON.stringify({ body: JSON.stringify({
loginName, loginName,
sessionId,
organization, organization,
webAuthN: { credentialAssertionData: data }, webAuthN: { credentialAssertionData: data },
authRequestId, authRequestId,
@@ -207,7 +212,15 @@ export default function LoginPasskey({
type="button" type="button"
variant={ButtonVariants.Secondary} variant={ButtonVariants.Secondary}
onClick={() => { onClick={() => {
const params: any = { loginName, alt: "true" }; const params: any = { alt: "true" };
if (loginName) {
params.loginName = loginName;
}
if (sessionId) {
params.sessionId = sessionId;
}
if (authRequestId) { if (authRequestId) {
params.authRequestId = authRequestId; params.authRequestId = authRequestId;