mirror of
https://github.com/zitadel/zitadel.git
synced 2025-12-12 05:44:36 +00:00
signin with context
This commit is contained in:
@@ -89,7 +89,7 @@ export default async function Page({
|
||||
searchParams: Record<string | number | symbol, string | undefined>;
|
||||
params: { provider: ProviderSlug };
|
||||
}) {
|
||||
const { id, token } = searchParams;
|
||||
const { id, token, authRequestId } = searchParams;
|
||||
const { provider } = params;
|
||||
|
||||
if (provider && id && token) {
|
||||
@@ -107,6 +107,7 @@ export default async function Page({
|
||||
<IdpSignin
|
||||
userId={userId}
|
||||
idpIntent={{ idpIntentId: id, idpIntentToken: token }}
|
||||
authRequestId={authRequestId}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -22,7 +22,13 @@ function getIdentityProviders(
|
||||
});
|
||||
}
|
||||
|
||||
export default async function Page() {
|
||||
export default async function Page({
|
||||
searchParams,
|
||||
}: {
|
||||
searchParams: Record<string | number | symbol, string | undefined>;
|
||||
}) {
|
||||
const authRequestId = searchParams?.authRequestId;
|
||||
|
||||
const legal = await getLegalAndSupportSettings(server);
|
||||
|
||||
// TODO if org idps should be shown replace emptystring with the orgId.
|
||||
@@ -43,6 +49,7 @@ export default async function Page() {
|
||||
<SignInWithIDP
|
||||
host={host}
|
||||
identityProviders={identityProviders}
|
||||
authRequestId={authRequestId}
|
||||
></SignInWithIDP>
|
||||
)}
|
||||
</div>
|
||||
|
||||
@@ -73,7 +73,6 @@ export async function PUT(request: NextRequest) {
|
||||
|
||||
return recentPromise
|
||||
.then((recent) => {
|
||||
console.log("setsession", webAuthN);
|
||||
return setSessionAndUpdateCookie(
|
||||
recent,
|
||||
password,
|
||||
|
||||
@@ -15,6 +15,7 @@ export interface SignInWithIDPProps {
|
||||
children?: ReactNode;
|
||||
host: string;
|
||||
identityProviders: any[];
|
||||
authRequestId?: string;
|
||||
startIDPFlowPath?: (idpId: string) => string;
|
||||
}
|
||||
|
||||
@@ -24,6 +25,7 @@ const START_IDP_FLOW_PATH = (idpId: string) =>
|
||||
export function SignInWithIDP({
|
||||
host,
|
||||
identityProviders,
|
||||
authRequestId,
|
||||
startIDPFlowPath = START_IDP_FLOW_PATH,
|
||||
}: SignInWithIDPProps) {
|
||||
const [loading, setLoading] = useState<boolean>(false);
|
||||
@@ -40,7 +42,10 @@ export function SignInWithIDP({
|
||||
},
|
||||
body: JSON.stringify({
|
||||
idpId,
|
||||
successUrl: `${host}/idp/${provider}/success`,
|
||||
successUrl: authRequestId
|
||||
? `${host}/idp/${provider}/success?` +
|
||||
new URLSearchParams({ authRequestId })
|
||||
: `${host}/idp/${provider}/success`,
|
||||
failureUrl: `${host}/idp/${provider}/failure`,
|
||||
}),
|
||||
});
|
||||
|
||||
@@ -44,15 +44,15 @@ export async function addSessionToCookie(
|
||||
currentSessions = [...currentSessions, session];
|
||||
}
|
||||
|
||||
if (cleanup) {
|
||||
const now = new Date();
|
||||
const filteredSessions = currentSessions.filter(
|
||||
(session) => new Date(session.expirationDate) > now
|
||||
);
|
||||
return setSessionHttpOnlyCookie(filteredSessions);
|
||||
} else {
|
||||
return setSessionHttpOnlyCookie(currentSessions);
|
||||
}
|
||||
// if (cleanup) {
|
||||
// const now = new Date();
|
||||
// const filteredSessions = currentSessions.filter(
|
||||
// (session) => new Date(session.expirationDate) > now
|
||||
// );
|
||||
// return setSessionHttpOnlyCookie(filteredSessions);
|
||||
// } else {
|
||||
return setSessionHttpOnlyCookie(currentSessions);
|
||||
// }
|
||||
}
|
||||
|
||||
export async function updateSessionCookie(
|
||||
@@ -71,15 +71,15 @@ export async function updateSessionCookie(
|
||||
|
||||
if (foundIndex > -1) {
|
||||
sessions[foundIndex] = session;
|
||||
if (cleanup) {
|
||||
const now = new Date();
|
||||
const filteredSessions = sessions.filter(
|
||||
(session) => new Date(session.expirationDate) > now
|
||||
);
|
||||
return setSessionHttpOnlyCookie(filteredSessions);
|
||||
} else {
|
||||
return setSessionHttpOnlyCookie(sessions);
|
||||
}
|
||||
// if (cleanup) {
|
||||
// const now = new Date();
|
||||
// const filteredSessions = sessions.filter(
|
||||
// (session) => new Date(session.expirationDate) > now
|
||||
// );
|
||||
// return setSessionHttpOnlyCookie(filteredSessions);
|
||||
// } else {
|
||||
return setSessionHttpOnlyCookie(sessions);
|
||||
// }
|
||||
} else {
|
||||
throw "updateSessionCookie: session id now found";
|
||||
}
|
||||
@@ -97,15 +97,15 @@ export async function removeSessionFromCookie(
|
||||
: [session];
|
||||
|
||||
const reducedSessions = sessions.filter((s) => s.id !== session.id);
|
||||
if (cleanup) {
|
||||
const now = new Date();
|
||||
const filteredSessions = reducedSessions.filter(
|
||||
(session) => new Date(session.expirationDate) > now
|
||||
);
|
||||
return setSessionHttpOnlyCookie(filteredSessions);
|
||||
} else {
|
||||
return setSessionHttpOnlyCookie(reducedSessions);
|
||||
}
|
||||
// if (cleanup) {
|
||||
// const now = new Date();
|
||||
// const filteredSessions = reducedSessions.filter(
|
||||
// (session) => new Date(session.expirationDate) > now
|
||||
// );
|
||||
// return setSessionHttpOnlyCookie(filteredSessions);
|
||||
// } else {
|
||||
return setSessionHttpOnlyCookie(reducedSessions);
|
||||
// }
|
||||
}
|
||||
|
||||
export async function getMostRecentSessionCookie(): Promise<any> {
|
||||
@@ -180,12 +180,14 @@ export async function getAllSessionCookieIds(
|
||||
if (stringifiedCookie?.value) {
|
||||
const sessions: SessionCookie[] = JSON.parse(stringifiedCookie?.value);
|
||||
|
||||
return sessions
|
||||
.filter((session) => {
|
||||
const now = new Date();
|
||||
cleanup ? new Date(session.expirationDate) > now : true;
|
||||
})
|
||||
.map((session) => session.id);
|
||||
// if (cleanup) {
|
||||
// const now = new Date();
|
||||
// return sessions
|
||||
// .filter((session) => new Date(session.expirationDate) > now)
|
||||
// .map((session) => session.id);
|
||||
// } else {
|
||||
return sessions.map((session) => session.id);
|
||||
// }
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
@@ -204,10 +206,15 @@ export async function getAllSessions(
|
||||
|
||||
if (stringifiedCookie?.value) {
|
||||
const sessions: SessionCookie[] = JSON.parse(stringifiedCookie?.value);
|
||||
return sessions.filter((session) => {
|
||||
const now = new Date();
|
||||
cleanup ? new Date(session.expirationDate) > now : true;
|
||||
});
|
||||
|
||||
// if (cleanup) {
|
||||
// const now = new Date();
|
||||
// return sessions.filter(
|
||||
// (session) => new Date(session.expirationDate) > now
|
||||
// );
|
||||
// } else {
|
||||
return sessions;
|
||||
// }
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user