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