mirror of
https://github.com/andwati/zitadel.git
synced 2026-11-22 12:58:46 +00:00
Merge commit from fork
* fix: Improve host header handling and deployment mode detection * ZITADEL_CLOUD env * refactor service config * service config * cleanup * cleanup * util for original and public host * instanceHost, publicHost * cleanup constructUrl * cleanup middleware * add x-zitadel-forward-host as fallback for current cloud setup * fix build * fix: lint * fix: update test mocks * fix: provide basepath to unit tests * host handling * unit tests * imports * fix: getPublicHost instead of getInstanceHost * unit tests * update nextjs, implement jwt verify for logout_token * pass logout information in jwt to login v2 * handle hosts in jwks url * point idp callbacks to the api and not the login UI * logout_hint out of logout token, typecheck * rm unused imports * fix oidc integration test --------- Co-authored-by: Livio Spring <[email protected]>
This commit is contained in:
co-authored by
Livio Spring
parent
f9e3871bb3
commit
df75be96ff
@@ -2,8 +2,8 @@ import { DynamicTheme } from "@/components/dynamic-theme";
|
||||
import { SessionsList } from "@/components/sessions-list";
|
||||
import { Translated } from "@/components/translated";
|
||||
import { getAllSessionCookieIds } from "@/lib/cookies";
|
||||
import { getServiceUrlFromHeaders } from "@/lib/service-url";
|
||||
import { getBrandingSettings, getDefaultOrg, listSessions } from "@/lib/zitadel";
|
||||
import { getServiceConfig } from "@/lib/service-url";
|
||||
import { getBrandingSettings, getDefaultOrg, listSessions, ServiceConfig } from "@/lib/zitadel";
|
||||
import { UserPlusIcon } from "@heroicons/react/24/outline";
|
||||
import { Organization } from "@zitadel/proto/zitadel/org/v2/org_pb";
|
||||
import { Metadata } from "next";
|
||||
@@ -17,13 +17,11 @@ export async function generateMetadata(): Promise<Metadata> {
|
||||
return { title: t("title") };
|
||||
}
|
||||
|
||||
async function loadSessions({ serviceUrl }: { serviceUrl: string }) {
|
||||
async function loadSessions({ serviceConfig }: { serviceConfig: ServiceConfig }) {
|
||||
const cookieIds = await getAllSessionCookieIds();
|
||||
|
||||
if (cookieIds && cookieIds.length) {
|
||||
const response = await listSessions({
|
||||
serviceUrl,
|
||||
ids: cookieIds.filter((id) => !!id) as string[],
|
||||
const response = await listSessions({ serviceConfig, ids: cookieIds.filter((id) => !!id) as string[],
|
||||
});
|
||||
return response?.sessions ?? [];
|
||||
} else {
|
||||
@@ -39,23 +37,19 @@ export default async function Page(props: { searchParams: Promise<Record<string
|
||||
const organization = searchParams?.organization;
|
||||
|
||||
const _headers = await headers();
|
||||
const { serviceUrl } = getServiceUrlFromHeaders(_headers);
|
||||
const { serviceConfig } = getServiceConfig(_headers);
|
||||
|
||||
let defaultOrganization;
|
||||
if (!organization) {
|
||||
const org: Organization | null = await getDefaultOrg({
|
||||
serviceUrl,
|
||||
});
|
||||
const org: Organization | null = await getDefaultOrg({ serviceConfig, });
|
||||
if (org) {
|
||||
defaultOrganization = org.id;
|
||||
}
|
||||
}
|
||||
|
||||
let sessions = await loadSessions({ serviceUrl });
|
||||
let sessions = await loadSessions({ serviceConfig });
|
||||
|
||||
const branding = await getBrandingSettings({
|
||||
serviceUrl,
|
||||
organization: organization ?? defaultOrganization,
|
||||
const branding = await getBrandingSettings({ serviceConfig, organization: organization ?? defaultOrganization,
|
||||
});
|
||||
|
||||
const params = new URLSearchParams();
|
||||
|
||||
@@ -6,7 +6,7 @@ import { SignInWithIdp } from "@/components/sign-in-with-idp";
|
||||
import { Translated } from "@/components/translated";
|
||||
import { UserAvatar } from "@/components/user-avatar";
|
||||
import { getSessionCookieById } from "@/lib/cookies";
|
||||
import { getServiceUrlFromHeaders } from "@/lib/service-url";
|
||||
import { getServiceConfig } from "@/lib/service-url";
|
||||
import { loadMostRecentSession } from "@/lib/session";
|
||||
import { checkUserVerification } from "@/lib/verify-helper";
|
||||
import {
|
||||
@@ -35,7 +35,7 @@ export default async function Page(props: { searchParams: Promise<Record<string
|
||||
const { loginName, requestId, organization, sessionId } = searchParams;
|
||||
|
||||
const _headers = await headers();
|
||||
const { serviceUrl } = getServiceUrlFromHeaders(_headers);
|
||||
const { serviceConfig } = getServiceConfig(_headers);
|
||||
|
||||
const sessionWithData = sessionId
|
||||
? await loadSessionById(sessionId, organization)
|
||||
@@ -52,11 +52,9 @@ export default async function Page(props: { searchParams: Promise<Record<string
|
||||
throw Error("Could not get user id from session");
|
||||
}
|
||||
|
||||
return listAuthenticationMethodTypes({
|
||||
serviceUrl,
|
||||
userId,
|
||||
return listAuthenticationMethodTypes({ serviceConfig, userId,
|
||||
}).then((methods) => {
|
||||
return getUserByID({ serviceUrl, userId }).then((user) => {
|
||||
return getUserByID({ serviceConfig, userId }).then((user) => {
|
||||
const humanUser = user.user?.type.case === "human" ? user.user?.type.value : undefined;
|
||||
|
||||
return {
|
||||
@@ -71,25 +69,21 @@ export default async function Page(props: { searchParams: Promise<Record<string
|
||||
}
|
||||
|
||||
async function loadSessionByLoginname(loginName?: string, organization?: string) {
|
||||
return loadMostRecentSession({
|
||||
serviceUrl,
|
||||
sessionParams: {
|
||||
return loadMostRecentSession({ serviceConfig, sessionParams: {
|
||||
loginName,
|
||||
organization,
|
||||
},
|
||||
}).then((session) => {
|
||||
return getAuthMethodsAndUser(serviceUrl, session);
|
||||
return getAuthMethodsAndUser(serviceConfig.baseUrl, session);
|
||||
});
|
||||
}
|
||||
|
||||
async function loadSessionById(sessionId: string, organization?: string) {
|
||||
const recent = await getSessionCookieById({ sessionId, organization });
|
||||
return getSession({
|
||||
serviceUrl,
|
||||
sessionId: recent.id,
|
||||
return getSession({ serviceConfig, sessionId: recent.id,
|
||||
sessionToken: recent.token,
|
||||
}).then((sessionResponse) => {
|
||||
return getAuthMethodsAndUser(serviceUrl, sessionResponse.session);
|
||||
return getAuthMethodsAndUser(serviceConfig.baseUrl, sessionResponse.session);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -101,14 +95,10 @@ export default async function Page(props: { searchParams: Promise<Record<string
|
||||
);
|
||||
}
|
||||
|
||||
const branding = await getBrandingSettings({
|
||||
serviceUrl,
|
||||
organization: sessionWithData.factors.user?.organizationId,
|
||||
const branding = await getBrandingSettings({ serviceConfig, organization: sessionWithData.factors.user?.organizationId,
|
||||
});
|
||||
|
||||
const loginSettings = await getLoginSettings({
|
||||
serviceUrl,
|
||||
organization: sessionWithData.factors.user?.organizationId,
|
||||
const loginSettings = await getLoginSettings({ serviceConfig, organization: sessionWithData.factors.user?.organizationId,
|
||||
});
|
||||
|
||||
// check if user was verified recently
|
||||
@@ -132,9 +122,7 @@ export default async function Page(props: { searchParams: Promise<Record<string
|
||||
redirect(`/verify?` + params);
|
||||
}
|
||||
|
||||
const identityProviders = await getActiveIdentityProviders({
|
||||
serviceUrl,
|
||||
orgId: sessionWithData.factors?.user?.organizationId,
|
||||
const identityProviders = await getActiveIdentityProviders({ serviceConfig, orgId: sessionWithData.factors?.user?.organizationId,
|
||||
linking_allowed: true,
|
||||
}).then((resp) => {
|
||||
return resp.identityProviders;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { ConsentScreen } from "@/components/consent";
|
||||
import { DynamicTheme } from "@/components/dynamic-theme";
|
||||
import { Translated } from "@/components/translated";
|
||||
import { getServiceUrlFromHeaders } from "@/lib/service-url";
|
||||
import { getServiceConfig } from "@/lib/service-url";
|
||||
import { getBrandingSettings, getDefaultOrg, getDeviceAuthorizationRequest } from "@/lib/zitadel";
|
||||
import { Organization } from "@zitadel/proto/zitadel/org/v2/org_pb";
|
||||
import { headers } from "next/headers";
|
||||
@@ -22,11 +22,9 @@ export default async function Page(props: { searchParams: Promise<Record<string
|
||||
}
|
||||
|
||||
const _headers = await headers();
|
||||
const { serviceUrl } = getServiceUrlFromHeaders(_headers);
|
||||
const { serviceConfig } = getServiceConfig(_headers);
|
||||
|
||||
const { deviceAuthorizationRequest } = await getDeviceAuthorizationRequest({
|
||||
serviceUrl,
|
||||
userCode,
|
||||
const { deviceAuthorizationRequest } = await getDeviceAuthorizationRequest({ serviceConfig, userCode,
|
||||
});
|
||||
|
||||
if (!deviceAuthorizationRequest) {
|
||||
@@ -39,17 +37,13 @@ export default async function Page(props: { searchParams: Promise<Record<string
|
||||
|
||||
let defaultOrganization;
|
||||
if (!organization) {
|
||||
const org: Organization | null = await getDefaultOrg({
|
||||
serviceUrl,
|
||||
});
|
||||
const org: Organization | null = await getDefaultOrg({ serviceConfig, });
|
||||
if (org) {
|
||||
defaultOrganization = org.id;
|
||||
}
|
||||
}
|
||||
|
||||
const branding = await getBrandingSettings({
|
||||
serviceUrl,
|
||||
organization: organization ?? defaultOrganization,
|
||||
const branding = await getBrandingSettings({ serviceConfig, organization: organization ?? defaultOrganization,
|
||||
});
|
||||
|
||||
const params = new URLSearchParams();
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { DeviceCodeForm } from "@/components/device-code-form";
|
||||
import { DynamicTheme } from "@/components/dynamic-theme";
|
||||
import { Translated } from "@/components/translated";
|
||||
import { getServiceUrlFromHeaders } from "@/lib/service-url";
|
||||
import { getServiceConfig } from "@/lib/service-url";
|
||||
import { getBrandingSettings, getDefaultOrg } from "@/lib/zitadel";
|
||||
import { Organization } from "@zitadel/proto/zitadel/org/v2/org_pb";
|
||||
import { Metadata } from "next";
|
||||
@@ -20,21 +20,17 @@ export default async function Page(props: { searchParams: Promise<Record<string
|
||||
const organization = searchParams?.organization;
|
||||
|
||||
const _headers = await headers();
|
||||
const { serviceUrl } = getServiceUrlFromHeaders(_headers);
|
||||
const { serviceConfig } = getServiceConfig(_headers);
|
||||
|
||||
let defaultOrganization;
|
||||
if (!organization) {
|
||||
const org: Organization | null = await getDefaultOrg({
|
||||
serviceUrl,
|
||||
});
|
||||
const org: Organization | null = await getDefaultOrg({ serviceConfig, });
|
||||
if (org) {
|
||||
defaultOrganization = org.id;
|
||||
}
|
||||
}
|
||||
|
||||
const branding = await getBrandingSettings({
|
||||
serviceUrl,
|
||||
organization: organization ?? defaultOrganization,
|
||||
const branding = await getBrandingSettings({ serviceConfig, organization: organization ?? defaultOrganization,
|
||||
});
|
||||
|
||||
return (
|
||||
|
||||
@@ -2,7 +2,7 @@ import { Alert, AlertType } from "@/components/alert";
|
||||
import { Button } from "@/components/button";
|
||||
import { DynamicTheme } from "@/components/dynamic-theme";
|
||||
import { Translated } from "@/components/translated";
|
||||
import { getServiceUrlFromHeaders } from "@/lib/service-url";
|
||||
import { getServiceConfig } from "@/lib/service-url";
|
||||
import { getBrandingSettings, getDefaultOrg } from "@/lib/zitadel";
|
||||
import { Organization } from "@zitadel/proto/zitadel/org/v2/org_pb";
|
||||
import { Metadata } from "next";
|
||||
@@ -20,21 +20,17 @@ export default async function Page(props: { searchParams: Promise<Record<string
|
||||
const { organization, postErrorRedirectUrl } = searchParams;
|
||||
|
||||
const _headers = await headers();
|
||||
const { serviceUrl } = getServiceUrlFromHeaders(_headers);
|
||||
const { serviceConfig } = getServiceConfig(_headers);
|
||||
|
||||
let defaultOrganization;
|
||||
if (!organization) {
|
||||
const org: Organization | null = await getDefaultOrg({
|
||||
serviceUrl,
|
||||
});
|
||||
const org: Organization | null = await getDefaultOrg({ serviceConfig, });
|
||||
if (org) {
|
||||
defaultOrganization = org.id;
|
||||
}
|
||||
}
|
||||
|
||||
const branding = await getBrandingSettings({
|
||||
serviceUrl,
|
||||
organization: organization ?? defaultOrganization,
|
||||
const branding = await getBrandingSettings({ serviceConfig, organization: organization ?? defaultOrganization,
|
||||
});
|
||||
|
||||
return (
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { DynamicTheme } from "@/components/dynamic-theme";
|
||||
import { RegisterFormIDPIncomplete } from "@/components/register-form-idp-incomplete";
|
||||
import { Translated } from "@/components/translated";
|
||||
import { getServiceUrlFromHeaders } from "@/lib/service-url";
|
||||
import { getServiceConfig } from "@/lib/service-url";
|
||||
import { getBrandingSettings } from "@/lib/zitadel";
|
||||
import { headers } from "next/headers";
|
||||
|
||||
@@ -16,11 +16,9 @@ export default async function CompleteRegistrationPage(props: {
|
||||
const { id, token, requestId, organization, idpId, idpUserId, idpUserName, givenName, familyName, email } = searchParams;
|
||||
|
||||
const _headers = await headers();
|
||||
const { serviceUrl } = getServiceUrlFromHeaders(_headers);
|
||||
const { serviceConfig } = getServiceConfig(_headers);
|
||||
|
||||
const branding = await getBrandingSettings({
|
||||
serviceUrl,
|
||||
organization,
|
||||
const branding = await getBrandingSettings({ serviceConfig, organization,
|
||||
});
|
||||
|
||||
if (!id || !token || !idpId || !organization || !idpUserId || !idpUserName) {
|
||||
|
||||
@@ -3,7 +3,7 @@ import { ChooseAuthenticatorToLogin } from "@/components/choose-authenticator-to
|
||||
import { DynamicTheme } from "@/components/dynamic-theme";
|
||||
import { Translated } from "@/components/translated";
|
||||
import { UserAvatar } from "@/components/user-avatar";
|
||||
import { getServiceUrlFromHeaders } from "@/lib/service-url";
|
||||
import { getServiceConfig } from "@/lib/service-url";
|
||||
import { getBrandingSettings, getLoginSettings, getUserByID, listAuthenticationMethodTypes } from "@/lib/zitadel";
|
||||
import { HumanUser, User } from "@zitadel/proto/zitadel/user/v2/user_pb";
|
||||
import { AuthenticationMethodType } from "@zitadel/proto/zitadel/user/v2/user_service_pb";
|
||||
@@ -18,16 +18,12 @@ export default async function Page(props: {
|
||||
const { organization, userId } = searchParams;
|
||||
|
||||
const _headers = await headers();
|
||||
const { serviceUrl } = getServiceUrlFromHeaders(_headers);
|
||||
const { serviceConfig } = getServiceConfig(_headers);
|
||||
|
||||
const branding = await getBrandingSettings({
|
||||
serviceUrl,
|
||||
organization,
|
||||
const branding = await getBrandingSettings({ serviceConfig, organization,
|
||||
});
|
||||
|
||||
const loginSettings = await getLoginSettings({
|
||||
serviceUrl,
|
||||
organization,
|
||||
const loginSettings = await getLoginSettings({ serviceConfig, organization,
|
||||
});
|
||||
|
||||
let authMethods: AuthenticationMethodType[] = [];
|
||||
@@ -43,9 +39,7 @@ export default async function Page(props: {
|
||||
}
|
||||
|
||||
if (userId) {
|
||||
const userResponse = await getUserByID({
|
||||
serviceUrl,
|
||||
userId,
|
||||
const userResponse = await getUserByID({ serviceConfig, userId,
|
||||
});
|
||||
if (userResponse) {
|
||||
user = userResponse.user;
|
||||
@@ -58,9 +52,7 @@ export default async function Page(props: {
|
||||
}
|
||||
}
|
||||
|
||||
const authMethodsResponse = await listAuthenticationMethodTypes({
|
||||
serviceUrl,
|
||||
userId,
|
||||
const authMethodsResponse = await listAuthenticationMethodTypes({ serviceConfig, userId,
|
||||
});
|
||||
if (authMethodsResponse.authMethodTypes) {
|
||||
authMethods = authMethodsResponse.authMethodTypes;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { DynamicTheme } from "@/components/dynamic-theme";
|
||||
import { Translated } from "@/components/translated";
|
||||
import { getServiceUrlFromHeaders } from "@/lib/service-url";
|
||||
import { getServiceConfig } from "@/lib/service-url";
|
||||
import { getBrandingSettings } from "@/lib/zitadel";
|
||||
import { headers } from "next/headers";
|
||||
|
||||
@@ -15,11 +15,9 @@ export default async function LinkingFailedPage(props: {
|
||||
const { organization, error } = searchParams;
|
||||
|
||||
const _headers = await headers();
|
||||
const { serviceUrl } = getServiceUrlFromHeaders(_headers);
|
||||
const { serviceConfig } = getServiceConfig(_headers);
|
||||
|
||||
const branding = await getBrandingSettings({
|
||||
serviceUrl,
|
||||
organization,
|
||||
const branding = await getBrandingSettings({ serviceConfig, organization,
|
||||
});
|
||||
|
||||
return (
|
||||
|
||||
@@ -2,7 +2,7 @@ import { Alert, AlertType } from "@/components/alert";
|
||||
import { Button } from "@/components/button";
|
||||
import { DynamicTheme } from "@/components/dynamic-theme";
|
||||
import { Translated } from "@/components/translated";
|
||||
import { getServiceUrlFromHeaders } from "@/lib/service-url";
|
||||
import { getServiceConfig } from "@/lib/service-url";
|
||||
import { getBrandingSettings, getDefaultOrg } from "@/lib/zitadel";
|
||||
import { Organization } from "@zitadel/proto/zitadel/org/v2/org_pb";
|
||||
import { Metadata } from "next";
|
||||
@@ -20,21 +20,17 @@ export default async function Page(props: { searchParams: Promise<Record<string
|
||||
const { organization, postErrorRedirectUrl } = searchParams;
|
||||
|
||||
const _headers = await headers();
|
||||
const { serviceUrl } = getServiceUrlFromHeaders(_headers);
|
||||
const { serviceConfig } = getServiceConfig(_headers);
|
||||
|
||||
let defaultOrganization;
|
||||
if (!organization) {
|
||||
const org: Organization | null = await getDefaultOrg({
|
||||
serviceUrl,
|
||||
});
|
||||
const org: Organization | null = await getDefaultOrg({ serviceConfig, });
|
||||
if (org) {
|
||||
defaultOrganization = org.id;
|
||||
}
|
||||
}
|
||||
|
||||
const branding = await getBrandingSettings({
|
||||
serviceUrl,
|
||||
organization: organization ?? defaultOrganization,
|
||||
const branding = await getBrandingSettings({ serviceConfig, organization: organization ?? defaultOrganization,
|
||||
});
|
||||
|
||||
return (
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { DynamicTheme } from "@/components/dynamic-theme";
|
||||
import { LDAPUsernamePasswordForm } from "@/components/ldap-username-password-form";
|
||||
import { Translated } from "@/components/translated";
|
||||
import { getServiceUrlFromHeaders } from "@/lib/service-url";
|
||||
import { getServiceConfig } from "@/lib/service-url";
|
||||
import { getBrandingSettings, getDefaultOrg } from "@/lib/zitadel";
|
||||
import { Organization } from "@zitadel/proto/zitadel/org/v2/org_pb";
|
||||
import { headers } from "next/headers";
|
||||
@@ -18,21 +18,17 @@ export default async function Page(props: {
|
||||
}
|
||||
|
||||
const _headers = await headers();
|
||||
const { serviceUrl } = getServiceUrlFromHeaders(_headers);
|
||||
const { serviceConfig } = getServiceConfig(_headers);
|
||||
|
||||
let defaultOrganization;
|
||||
if (!organization) {
|
||||
const org: Organization | null = await getDefaultOrg({
|
||||
serviceUrl,
|
||||
});
|
||||
const org: Organization | null = await getDefaultOrg({ serviceConfig, });
|
||||
if (org) {
|
||||
defaultOrganization = org.id;
|
||||
}
|
||||
}
|
||||
|
||||
const branding = await getBrandingSettings({
|
||||
serviceUrl,
|
||||
organization: organization ?? defaultOrganization,
|
||||
const branding = await getBrandingSettings({ serviceConfig, organization: organization ?? defaultOrganization,
|
||||
});
|
||||
|
||||
// return login failed if no linking or creation is allowed and no user was found
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { DynamicTheme } from "@/components/dynamic-theme";
|
||||
import { SignInWithIdp } from "@/components/sign-in-with-idp";
|
||||
import { Translated } from "@/components/translated";
|
||||
import { getServiceUrlFromHeaders } from "@/lib/service-url";
|
||||
import { getServiceConfig } from "@/lib/service-url";
|
||||
import { getActiveIdentityProviders, getBrandingSettings } from "@/lib/zitadel";
|
||||
import { Metadata } from "next";
|
||||
import { getTranslations } from "next-intl/server";
|
||||
@@ -19,18 +19,14 @@ export default async function Page(props: { searchParams: Promise<Record<string
|
||||
const organization = searchParams?.organization;
|
||||
|
||||
const _headers = await headers();
|
||||
const { serviceUrl } = getServiceUrlFromHeaders(_headers);
|
||||
const { serviceConfig } = getServiceConfig(_headers);
|
||||
|
||||
const identityProviders = await getActiveIdentityProviders({
|
||||
serviceUrl,
|
||||
orgId: organization,
|
||||
const identityProviders = await getActiveIdentityProviders({ serviceConfig, orgId: organization,
|
||||
}).then((resp) => {
|
||||
return resp.identityProviders;
|
||||
});
|
||||
|
||||
const branding = await getBrandingSettings({
|
||||
serviceUrl,
|
||||
organization,
|
||||
const branding = await getBrandingSettings({ serviceConfig, organization,
|
||||
});
|
||||
|
||||
return (
|
||||
|
||||
@@ -2,7 +2,7 @@ import { DynamicTheme } from "@/components/dynamic-theme";
|
||||
import { SignInWithIdp } from "@/components/sign-in-with-idp";
|
||||
import { Translated } from "@/components/translated";
|
||||
import { UsernameForm } from "@/components/username-form";
|
||||
import { getServiceUrlFromHeaders } from "@/lib/service-url";
|
||||
import { getServiceConfig } from "@/lib/service-url";
|
||||
import { getActiveIdentityProviders, getBrandingSettings, getDefaultOrg, getLoginSettings } from "@/lib/zitadel";
|
||||
import { Organization } from "@zitadel/proto/zitadel/org/v2/org_pb";
|
||||
import { Metadata } from "next";
|
||||
@@ -24,38 +24,28 @@ export default async function Page(props: { searchParams: Promise<Record<string
|
||||
const submit: boolean = searchParams?.submit === "true";
|
||||
|
||||
const _headers = await headers();
|
||||
const { serviceUrl } = getServiceUrlFromHeaders(_headers);
|
||||
const { serviceConfig } = getServiceConfig(_headers);
|
||||
|
||||
let defaultOrganization;
|
||||
if (!organization) {
|
||||
const org: Organization | null = await getDefaultOrg({
|
||||
serviceUrl,
|
||||
});
|
||||
const org: Organization | null = await getDefaultOrg({ serviceConfig, });
|
||||
if (org) {
|
||||
defaultOrganization = org.id;
|
||||
}
|
||||
}
|
||||
|
||||
const loginSettings = await getLoginSettings({
|
||||
serviceUrl,
|
||||
organization: organization ?? defaultOrganization,
|
||||
const loginSettings = await getLoginSettings({ serviceConfig, organization: organization ?? defaultOrganization,
|
||||
});
|
||||
|
||||
const contextLoginSettings = await getLoginSettings({
|
||||
serviceUrl,
|
||||
organization,
|
||||
const contextLoginSettings = await getLoginSettings({ serviceConfig, organization,
|
||||
});
|
||||
|
||||
const identityProviders = await getActiveIdentityProviders({
|
||||
serviceUrl,
|
||||
orgId: organization ?? defaultOrganization,
|
||||
const identityProviders = await getActiveIdentityProviders({ serviceConfig, orgId: organization ?? defaultOrganization,
|
||||
}).then((resp) => {
|
||||
return resp.identityProviders;
|
||||
});
|
||||
|
||||
const branding = await getBrandingSettings({
|
||||
serviceUrl,
|
||||
organization: organization ?? defaultOrganization,
|
||||
const branding = await getBrandingSettings({ serviceConfig, organization: organization ?? defaultOrganization,
|
||||
});
|
||||
|
||||
return (
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { DynamicTheme } from "@/components/dynamic-theme";
|
||||
import { Translated } from "@/components/translated";
|
||||
import { getServiceUrlFromHeaders } from "@/lib/service-url";
|
||||
import { getServiceConfig } from "@/lib/service-url";
|
||||
import { getBrandingSettings } from "@/lib/zitadel";
|
||||
import { headers } from "next/headers";
|
||||
|
||||
@@ -8,13 +8,11 @@ export default async function Page(props: { searchParams: Promise<any> }) {
|
||||
const searchParams = await props.searchParams;
|
||||
|
||||
const _headers = await headers();
|
||||
const { serviceUrl } = getServiceUrlFromHeaders(_headers);
|
||||
const { serviceConfig } = getServiceConfig(_headers);
|
||||
|
||||
const { organization } = searchParams;
|
||||
|
||||
const branding = await getBrandingSettings({
|
||||
serviceUrl,
|
||||
organization,
|
||||
const branding = await getBrandingSettings({ serviceConfig, organization,
|
||||
});
|
||||
|
||||
return (
|
||||
|
||||
@@ -2,8 +2,9 @@ import { DynamicTheme } from "@/components/dynamic-theme";
|
||||
import { SessionsClearList } from "@/components/sessions-clear-list";
|
||||
import { Translated } from "@/components/translated";
|
||||
import { getAllSessionCookieIds } from "@/lib/cookies";
|
||||
import { getServiceUrlFromHeaders } from "@/lib/service-url";
|
||||
import { getBrandingSettings, getDefaultOrg, listSessions } from "@/lib/zitadel";
|
||||
import { getServiceConfig } from "@/lib/service-url";
|
||||
import { getBrandingSettings, getDefaultOrg, listSessions, ServiceConfig } from "@/lib/zitadel";
|
||||
import { verifyJwt } from "@zitadel/client/node";
|
||||
import { Organization } from "@zitadel/proto/zitadel/org/v2/org_pb";
|
||||
import { Metadata } from "next";
|
||||
import { getTranslations } from "next-intl/server";
|
||||
@@ -11,17 +12,14 @@ import { headers } from "next/headers";
|
||||
|
||||
export async function generateMetadata(): Promise<Metadata> {
|
||||
const t = await getTranslations("logout");
|
||||
return { title: t('title')};
|
||||
return { title: t("title") };
|
||||
}
|
||||
|
||||
async function loadSessions({ serviceUrl }: { serviceUrl: string }) {
|
||||
async function loadSessions({ serviceConfig }: { serviceConfig: ServiceConfig }) {
|
||||
const cookieIds = await getAllSessionCookieIds();
|
||||
|
||||
if (cookieIds && cookieIds.length) {
|
||||
const response = await listSessions({
|
||||
serviceUrl,
|
||||
ids: cookieIds.filter((id) => !!id) as string[],
|
||||
});
|
||||
const response = await listSessions({ serviceConfig, ids: cookieIds.filter((id) => !!id) as string[] });
|
||||
return response?.sessions ?? [];
|
||||
} else {
|
||||
console.info("No session cookie found.");
|
||||
@@ -33,30 +31,46 @@ export default async function Page(props: { searchParams: Promise<Record<string
|
||||
const searchParams = await props.searchParams;
|
||||
|
||||
const organization = searchParams?.organization;
|
||||
const postLogoutRedirectUri = searchParams?.post_logout_redirect || searchParams?.post_logout_redirect_uri;
|
||||
const logoutHint = searchParams?.logout_hint;
|
||||
// TODO implement with new translation service
|
||||
// const UILocales = searchParams?.ui_locales;
|
||||
const logoutToken = searchParams?.logout_token;
|
||||
|
||||
const _headers = await headers();
|
||||
const { serviceUrl } = getServiceUrlFromHeaders(_headers);
|
||||
const { serviceConfig } = getServiceConfig(_headers);
|
||||
|
||||
let postLogoutRedirectUri, logoutHint;
|
||||
if (logoutToken) {
|
||||
try {
|
||||
const payload = await verifyJwt<{ post_logout_redirect_uri?: string; logoutHint?: string }>(
|
||||
logoutToken,
|
||||
`${serviceConfig.baseUrl}/oauth/v2/keys`,
|
||||
{
|
||||
instanceHost: serviceConfig.instanceHost,
|
||||
publicHost: serviceConfig.publicHost,
|
||||
},
|
||||
);
|
||||
console.log("logout token payload", payload);
|
||||
|
||||
if (payload.post_logout_redirect_uri && typeof payload.post_logout_redirect_uri === "string") {
|
||||
postLogoutRedirectUri = payload.post_logout_redirect_uri;
|
||||
}
|
||||
if (payload.logout_hint && typeof payload.logout_hint === "string") {
|
||||
logoutHint = payload.logout_hint;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Failed to verify logout token", error);
|
||||
}
|
||||
}
|
||||
|
||||
let defaultOrganization;
|
||||
if (!organization) {
|
||||
const org: Organization | null = await getDefaultOrg({
|
||||
serviceUrl,
|
||||
});
|
||||
const org: Organization | null = await getDefaultOrg({ serviceConfig });
|
||||
if (org) {
|
||||
defaultOrganization = org.id;
|
||||
}
|
||||
}
|
||||
|
||||
let sessions = await loadSessions({ serviceUrl });
|
||||
let sessions = await loadSessions({ serviceConfig });
|
||||
|
||||
const branding = await getBrandingSettings({
|
||||
serviceUrl,
|
||||
organization: organization ?? defaultOrganization,
|
||||
});
|
||||
const branding = await getBrandingSettings({ serviceConfig, organization: organization ?? defaultOrganization });
|
||||
|
||||
const params = new URLSearchParams();
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ import { DynamicTheme } from "@/components/dynamic-theme";
|
||||
import { Translated } from "@/components/translated";
|
||||
import { UserAvatar } from "@/components/user-avatar";
|
||||
import { getSessionCookieById } from "@/lib/cookies";
|
||||
import { getServiceUrlFromHeaders } from "@/lib/service-url";
|
||||
import { getServiceConfig } from "@/lib/service-url";
|
||||
import { loadMostRecentSession } from "@/lib/session";
|
||||
import { getBrandingSettings, getSession, listAuthenticationMethodTypes } from "@/lib/zitadel";
|
||||
import { Metadata } from "next";
|
||||
@@ -23,24 +23,20 @@ export default async function Page(props: { searchParams: Promise<Record<string
|
||||
const { loginName, requestId, organization, sessionId } = searchParams;
|
||||
|
||||
const _headers = await headers();
|
||||
const { serviceUrl } = getServiceUrlFromHeaders(_headers);
|
||||
const { serviceConfig } = getServiceConfig(_headers);
|
||||
|
||||
const sessionFactors = sessionId
|
||||
? await loadSessionById(serviceUrl, sessionId, organization)
|
||||
: await loadSessionByLoginname(serviceUrl, loginName, organization);
|
||||
? await loadSessionById(serviceConfig.baseUrl, sessionId, organization)
|
||||
: await loadSessionByLoginname(serviceConfig.baseUrl, loginName, organization);
|
||||
|
||||
async function loadSessionByLoginname(serviceUrl: string, loginName?: string, organization?: string) {
|
||||
return loadMostRecentSession({
|
||||
serviceUrl,
|
||||
sessionParams: {
|
||||
return loadMostRecentSession({ serviceConfig, sessionParams: {
|
||||
loginName,
|
||||
organization,
|
||||
},
|
||||
}).then((session) => {
|
||||
if (session && session.factors?.user?.id) {
|
||||
return listAuthenticationMethodTypes({
|
||||
serviceUrl,
|
||||
userId: session.factors.user.id,
|
||||
return listAuthenticationMethodTypes({ serviceConfig, userId: session.factors.user.id,
|
||||
}).then((methods) => {
|
||||
return {
|
||||
factors: session?.factors,
|
||||
@@ -53,15 +49,11 @@ export default async function Page(props: { searchParams: Promise<Record<string
|
||||
|
||||
async function loadSessionById(host: string, sessionId: string, organization?: string) {
|
||||
const recent = await getSessionCookieById({ sessionId, organization });
|
||||
return getSession({
|
||||
serviceUrl,
|
||||
sessionId: recent.id,
|
||||
return getSession({ serviceConfig, sessionId: recent.id,
|
||||
sessionToken: recent.token,
|
||||
}).then((response) => {
|
||||
if (response?.session && response.session.factors?.user?.id) {
|
||||
return listAuthenticationMethodTypes({
|
||||
serviceUrl,
|
||||
userId: response.session.factors.user.id,
|
||||
return listAuthenticationMethodTypes({ serviceConfig, userId: response.session.factors.user.id,
|
||||
}).then((methods) => {
|
||||
return {
|
||||
factors: response.session?.factors,
|
||||
@@ -72,9 +64,7 @@ export default async function Page(props: { searchParams: Promise<Record<string
|
||||
});
|
||||
}
|
||||
|
||||
const branding = await getBrandingSettings({
|
||||
serviceUrl,
|
||||
organization,
|
||||
const branding = await getBrandingSettings({ serviceConfig, organization,
|
||||
});
|
||||
|
||||
return (
|
||||
|
||||
@@ -5,7 +5,7 @@ import { DynamicTheme } from "@/components/dynamic-theme";
|
||||
import { Translated } from "@/components/translated";
|
||||
import { UserAvatar } from "@/components/user-avatar";
|
||||
import { getSessionCookieById } from "@/lib/cookies";
|
||||
import { getServiceUrlFromHeaders } from "@/lib/service-url";
|
||||
import { getServiceConfig } from "@/lib/service-url";
|
||||
import { loadMostRecentSession } from "@/lib/session";
|
||||
import {
|
||||
getBrandingSettings,
|
||||
@@ -46,7 +46,7 @@ export default async function Page(props: { searchParams: Promise<Record<string
|
||||
const { loginName, checkAfter, force, requestId, organization, sessionId } = searchParams;
|
||||
|
||||
const _headers = await headers();
|
||||
const { serviceUrl } = getServiceUrlFromHeaders(_headers);
|
||||
const { serviceConfig } = getServiceConfig(_headers);
|
||||
|
||||
const sessionWithData = sessionId
|
||||
? await loadSessionById(sessionId, organization)
|
||||
@@ -59,11 +59,9 @@ export default async function Page(props: { searchParams: Promise<Record<string
|
||||
throw Error("Could not get user id from session");
|
||||
}
|
||||
|
||||
return listAuthenticationMethodTypes({
|
||||
serviceUrl,
|
||||
userId,
|
||||
return listAuthenticationMethodTypes({ serviceConfig, userId,
|
||||
}).then((methods) => {
|
||||
return getUserByID({ serviceUrl, userId }).then((user) => {
|
||||
return getUserByID({ serviceConfig, userId }).then((user) => {
|
||||
const humanUser = user.user?.type.case === "human" ? user.user?.type.value : undefined;
|
||||
|
||||
return {
|
||||
@@ -79,9 +77,7 @@ export default async function Page(props: { searchParams: Promise<Record<string
|
||||
}
|
||||
|
||||
async function loadSessionByLoginname(loginName?: string, organization?: string) {
|
||||
return loadMostRecentSession({
|
||||
serviceUrl,
|
||||
sessionParams: {
|
||||
return loadMostRecentSession({ serviceConfig, sessionParams: {
|
||||
loginName,
|
||||
organization,
|
||||
},
|
||||
@@ -92,22 +88,16 @@ export default async function Page(props: { searchParams: Promise<Record<string
|
||||
|
||||
async function loadSessionById(sessionId: string, organization?: string) {
|
||||
const recent = await getSessionCookieById({ sessionId, organization });
|
||||
return getSession({
|
||||
serviceUrl,
|
||||
sessionId: recent.id,
|
||||
return getSession({ serviceConfig, sessionId: recent.id,
|
||||
sessionToken: recent.token,
|
||||
}).then((sessionResponse) => {
|
||||
return getAuthMethodsAndUser(sessionResponse.session);
|
||||
});
|
||||
}
|
||||
|
||||
const branding = await getBrandingSettings({
|
||||
serviceUrl,
|
||||
organization,
|
||||
const branding = await getBrandingSettings({ serviceConfig, organization,
|
||||
});
|
||||
const loginSettings = await getLoginSettings({
|
||||
serviceUrl,
|
||||
organization: sessionWithData.factors?.user?.organizationId,
|
||||
const loginSettings = await getLoginSettings({ serviceConfig, organization: sessionWithData.factors?.user?.organizationId,
|
||||
});
|
||||
|
||||
const { valid } = isSessionValid(sessionWithData);
|
||||
|
||||
@@ -4,8 +4,8 @@ import { LoginOTP } from "@/components/login-otp";
|
||||
import { Translated } from "@/components/translated";
|
||||
import { UserAvatar } from "@/components/user-avatar";
|
||||
import { getSessionCookieById } from "@/lib/cookies";
|
||||
import { getOriginalHost } from "@/lib/server/host";
|
||||
import { getServiceUrlFromHeaders } from "@/lib/service-url";
|
||||
import { getPublicHost } from "@/lib/server/host";
|
||||
import { getServiceConfig } from "@/lib/service-url";
|
||||
import { loadMostRecentSession } from "@/lib/session";
|
||||
import { getBrandingSettings, getLoginSettings, getSession } from "@/lib/zitadel";
|
||||
import { Metadata } from "next";
|
||||
@@ -25,8 +25,8 @@ export default async function Page(props: {
|
||||
const searchParams = await props.searchParams;
|
||||
|
||||
const _headers = await headers();
|
||||
const { serviceUrl } = getServiceUrlFromHeaders(_headers);
|
||||
const host = await getOriginalHost();
|
||||
const { serviceConfig } = getServiceConfig(_headers);
|
||||
const host = getPublicHost(_headers);
|
||||
|
||||
const {
|
||||
loginName, // send from password page
|
||||
@@ -40,18 +40,11 @@ export default async function Page(props: {
|
||||
|
||||
const session = sessionId
|
||||
? await loadSessionById(sessionId, organization)
|
||||
: await loadMostRecentSession({
|
||||
serviceUrl,
|
||||
sessionParams: { loginName, organization },
|
||||
});
|
||||
: await loadMostRecentSession({ serviceConfig, sessionParams: { loginName, organization } });
|
||||
|
||||
async function loadSessionById(sessionId: string, organization?: string) {
|
||||
const recent = await getSessionCookieById({ sessionId, organization });
|
||||
return getSession({
|
||||
serviceUrl,
|
||||
sessionId: recent.id,
|
||||
sessionToken: recent.token,
|
||||
}).then((response) => {
|
||||
return getSession({ serviceConfig, sessionId: recent.id, sessionToken: recent.token }).then((response) => {
|
||||
if (response?.session) {
|
||||
return response.session;
|
||||
}
|
||||
@@ -60,12 +53,12 @@ export default async function Page(props: {
|
||||
|
||||
// email links do not come with organization, thus we need to use the session's organization
|
||||
const branding = await getBrandingSettings({
|
||||
serviceUrl,
|
||||
serviceConfig,
|
||||
organization: organization ?? session?.factors?.user?.organizationId,
|
||||
});
|
||||
|
||||
const loginSettings = await getLoginSettings({
|
||||
serviceUrl,
|
||||
serviceConfig,
|
||||
organization: organization ?? session?.factors?.user?.organizationId,
|
||||
});
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ import { DynamicTheme } from "@/components/dynamic-theme";
|
||||
import { TotpRegister } from "@/components/totp-register";
|
||||
import { Translated } from "@/components/translated";
|
||||
import { UserAvatar } from "@/components/user-avatar";
|
||||
import { getServiceUrlFromHeaders } from "@/lib/service-url";
|
||||
import { getServiceConfig } from "@/lib/service-url";
|
||||
import { loadMostRecentSession } from "@/lib/session";
|
||||
import { addOTPEmail, addOTPSMS, getBrandingSettings, getLoginSettings, registerTOTP } from "@/lib/zitadel";
|
||||
import { RegisterTOTPResponse } from "@zitadel/proto/zitadel/user/v2/user_service_pb";
|
||||
@@ -24,20 +24,14 @@ export default async function Page(props: {
|
||||
const { method } = params;
|
||||
|
||||
const _headers = await headers();
|
||||
const { serviceUrl } = getServiceUrlFromHeaders(_headers);
|
||||
const { serviceConfig } = getServiceConfig(_headers);
|
||||
|
||||
const branding = await getBrandingSettings({
|
||||
serviceUrl,
|
||||
organization,
|
||||
const branding = await getBrandingSettings({ serviceConfig, organization,
|
||||
});
|
||||
const loginSettings = await getLoginSettings({
|
||||
serviceUrl,
|
||||
organization,
|
||||
const loginSettings = await getLoginSettings({ serviceConfig, organization,
|
||||
});
|
||||
|
||||
const session = await loadMostRecentSession({
|
||||
serviceUrl,
|
||||
sessionParams: {
|
||||
const session = await loadMostRecentSession({ serviceConfig, sessionParams: {
|
||||
loginName,
|
||||
organization,
|
||||
},
|
||||
@@ -46,9 +40,7 @@ export default async function Page(props: {
|
||||
let totpResponse: RegisterTOTPResponse | undefined, error: Error | undefined;
|
||||
if (session && session.factors?.user?.id) {
|
||||
if (method === "time-based") {
|
||||
await registerTOTP({
|
||||
serviceUrl,
|
||||
userId: session.factors.user.id,
|
||||
await registerTOTP({ serviceConfig, userId: session.factors.user.id,
|
||||
})
|
||||
.then((resp) => {
|
||||
if (resp) {
|
||||
@@ -59,17 +51,13 @@ export default async function Page(props: {
|
||||
error = err;
|
||||
});
|
||||
} else if (method === "sms") {
|
||||
await addOTPSMS({
|
||||
serviceUrl,
|
||||
userId: session.factors.user.id,
|
||||
await addOTPSMS({ serviceConfig, userId: session.factors.user.id,
|
||||
}).catch((_error) => {
|
||||
// TODO: Throw this error?
|
||||
new Error("Could not add OTP via SMS");
|
||||
});
|
||||
} else if (method === "email") {
|
||||
await addOTPEmail({
|
||||
serviceUrl,
|
||||
userId: session.factors.user.id,
|
||||
await addOTPEmail({ serviceConfig, userId: session.factors.user.id,
|
||||
}).catch((_error) => {
|
||||
// TODO: Throw this error?
|
||||
new Error("Could not add OTP via Email");
|
||||
|
||||
@@ -4,7 +4,7 @@ import { LoginPasskey } from "@/components/login-passkey";
|
||||
import { Translated } from "@/components/translated";
|
||||
import { UserAvatar } from "@/components/user-avatar";
|
||||
import { getSessionCookieById } from "@/lib/cookies";
|
||||
import { getServiceUrlFromHeaders } from "@/lib/service-url";
|
||||
import { getServiceConfig } from "@/lib/service-url";
|
||||
import { loadMostRecentSession } from "@/lib/session";
|
||||
import { getBrandingSettings, getSession } from "@/lib/zitadel";
|
||||
import { Metadata } from "next";
|
||||
@@ -22,20 +22,16 @@ export default async function Page(props: { searchParams: Promise<Record<string
|
||||
const { loginName, altPassword, requestId, organization, sessionId } = searchParams;
|
||||
|
||||
const _headers = await headers();
|
||||
const { serviceUrl } = getServiceUrlFromHeaders(_headers);
|
||||
const { serviceConfig } = getServiceConfig(_headers);
|
||||
|
||||
const sessionFactors = sessionId
|
||||
? await loadSessionById(serviceUrl, sessionId, organization)
|
||||
: await loadMostRecentSession({
|
||||
serviceUrl,
|
||||
sessionParams: { loginName, organization },
|
||||
? await loadSessionById(serviceConfig.baseUrl, sessionId, organization)
|
||||
: await loadMostRecentSession({ serviceConfig, sessionParams: { loginName, organization },
|
||||
});
|
||||
|
||||
async function loadSessionById(serviceUrl: string, sessionId: string, organization?: string) {
|
||||
const recent = await getSessionCookieById({ sessionId, organization });
|
||||
return getSession({
|
||||
serviceUrl,
|
||||
sessionId: recent.id,
|
||||
return getSession({ serviceConfig, sessionId: recent.id,
|
||||
sessionToken: recent.token,
|
||||
}).then((response) => {
|
||||
if (response?.session) {
|
||||
@@ -44,9 +40,7 @@ export default async function Page(props: { searchParams: Promise<Record<string
|
||||
});
|
||||
}
|
||||
|
||||
const branding = await getBrandingSettings({
|
||||
serviceUrl,
|
||||
organization,
|
||||
const branding = await getBrandingSettings({ serviceConfig, organization,
|
||||
});
|
||||
|
||||
return (
|
||||
|
||||
@@ -3,7 +3,7 @@ import { DynamicTheme } from "@/components/dynamic-theme";
|
||||
import { RegisterPasskey } from "@/components/register-passkey";
|
||||
import { Translated } from "@/components/translated";
|
||||
import { UserAvatar } from "@/components/user-avatar";
|
||||
import { getServiceUrlFromHeaders } from "@/lib/service-url";
|
||||
import { getServiceConfig } from "@/lib/service-url";
|
||||
import { loadMostRecentSession } from "@/lib/session";
|
||||
import { getBrandingSettings, getUserByID } from "@/lib/zitadel";
|
||||
import { Session } from "@zitadel/proto/zitadel/session/v2/session_pb";
|
||||
@@ -23,31 +23,25 @@ export default async function Page(props: { searchParams: Promise<Record<string
|
||||
const { userId, loginName, prompt, organization, requestId, code, codeId } = searchParams;
|
||||
|
||||
const _headers = await headers();
|
||||
const { serviceUrl } = getServiceUrlFromHeaders(_headers);
|
||||
const { serviceConfig } = getServiceConfig(_headers);
|
||||
|
||||
// also allow no session to be found for userId-based flows
|
||||
let session: Session | undefined;
|
||||
if (loginName) {
|
||||
session = await loadMostRecentSession({
|
||||
serviceUrl,
|
||||
sessionParams: {
|
||||
session = await loadMostRecentSession({ serviceConfig, sessionParams: {
|
||||
loginName,
|
||||
organization,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
const branding = await getBrandingSettings({
|
||||
serviceUrl,
|
||||
organization,
|
||||
const branding = await getBrandingSettings({ serviceConfig, organization,
|
||||
});
|
||||
|
||||
let user: User | undefined;
|
||||
let displayName: string | undefined;
|
||||
if (userId) {
|
||||
const userResponse = await getUserByID({
|
||||
serviceUrl,
|
||||
userId,
|
||||
const userResponse = await getUserByID({ serviceConfig, userId,
|
||||
});
|
||||
user = userResponse.user;
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ import { ChangePasswordForm } from "@/components/change-password-form";
|
||||
import { DynamicTheme } from "@/components/dynamic-theme";
|
||||
import { Translated } from "@/components/translated";
|
||||
import { UserAvatar } from "@/components/user-avatar";
|
||||
import { getServiceUrlFromHeaders } from "@/lib/service-url";
|
||||
import { getServiceConfig } from "@/lib/service-url";
|
||||
import { loadMostRecentSession } from "@/lib/session";
|
||||
import { getBrandingSettings, getLoginSettings, getPasswordComplexitySettings } from "@/lib/zitadel";
|
||||
import { Metadata } from "next";
|
||||
@@ -17,34 +17,26 @@ export async function generateMetadata(): Promise<Metadata> {
|
||||
|
||||
export default async function Page(props: { searchParams: Promise<Record<string | number | symbol, string | undefined>> }) {
|
||||
const _headers = await headers();
|
||||
const { serviceUrl } = getServiceUrlFromHeaders(_headers);
|
||||
const { serviceConfig } = getServiceConfig(_headers);
|
||||
|
||||
const searchParams = await props.searchParams;
|
||||
|
||||
const { loginName, organization, requestId } = searchParams;
|
||||
|
||||
// also allow no session to be found (ignoreUnkownUsername)
|
||||
const sessionFactors = await loadMostRecentSession({
|
||||
serviceUrl,
|
||||
sessionParams: {
|
||||
const sessionFactors = await loadMostRecentSession({ serviceConfig, sessionParams: {
|
||||
loginName,
|
||||
organization,
|
||||
},
|
||||
});
|
||||
|
||||
const branding = await getBrandingSettings({
|
||||
serviceUrl,
|
||||
organization,
|
||||
const branding = await getBrandingSettings({ serviceConfig, organization,
|
||||
});
|
||||
|
||||
const passwordComplexity = await getPasswordComplexitySettings({
|
||||
serviceUrl,
|
||||
organization: sessionFactors?.factors?.user?.organizationId,
|
||||
const passwordComplexity = await getPasswordComplexitySettings({ serviceConfig, organization: sessionFactors?.factors?.user?.organizationId,
|
||||
});
|
||||
|
||||
const loginSettings = await getLoginSettings({
|
||||
serviceUrl,
|
||||
organization: sessionFactors?.factors?.user?.organizationId,
|
||||
const loginSettings = await getLoginSettings({ serviceConfig, organization: sessionFactors?.factors?.user?.organizationId,
|
||||
});
|
||||
|
||||
return (
|
||||
|
||||
@@ -3,7 +3,7 @@ import { DynamicTheme } from "@/components/dynamic-theme";
|
||||
import { PasswordForm } from "@/components/password-form";
|
||||
import { Translated } from "@/components/translated";
|
||||
import { UserAvatar } from "@/components/user-avatar";
|
||||
import { getServiceUrlFromHeaders } from "@/lib/service-url";
|
||||
import { getServiceConfig } from "@/lib/service-url";
|
||||
import { loadMostRecentSession } from "@/lib/session";
|
||||
import { getBrandingSettings, getDefaultOrg, getLoginSettings } from "@/lib/zitadel";
|
||||
import { Organization } from "@zitadel/proto/zitadel/org/v2/org_pb";
|
||||
@@ -21,13 +21,11 @@ export default async function Page(props: { searchParams: Promise<Record<string
|
||||
let { loginName, organization, requestId } = searchParams;
|
||||
|
||||
const _headers = await headers();
|
||||
const { serviceUrl } = getServiceUrlFromHeaders(_headers);
|
||||
const { serviceConfig } = getServiceConfig(_headers);
|
||||
|
||||
let defaultOrganization;
|
||||
if (!organization) {
|
||||
const org: Organization | null = await getDefaultOrg({
|
||||
serviceUrl,
|
||||
});
|
||||
const org: Organization | null = await getDefaultOrg({ serviceConfig, });
|
||||
|
||||
if (org) {
|
||||
defaultOrganization = org.id;
|
||||
@@ -37,9 +35,7 @@ export default async function Page(props: { searchParams: Promise<Record<string
|
||||
// also allow no session to be found (ignoreUnkownUsername)
|
||||
let sessionFactors;
|
||||
try {
|
||||
sessionFactors = await loadMostRecentSession({
|
||||
serviceUrl,
|
||||
sessionParams: {
|
||||
sessionFactors = await loadMostRecentSession({ serviceConfig, sessionParams: {
|
||||
loginName,
|
||||
organization,
|
||||
},
|
||||
@@ -49,13 +45,9 @@ export default async function Page(props: { searchParams: Promise<Record<string
|
||||
console.warn(error);
|
||||
}
|
||||
|
||||
const branding = await getBrandingSettings({
|
||||
serviceUrl,
|
||||
organization: organization ?? defaultOrganization,
|
||||
const branding = await getBrandingSettings({ serviceConfig, organization: organization ?? defaultOrganization,
|
||||
});
|
||||
const loginSettings = await getLoginSettings({
|
||||
serviceUrl,
|
||||
organization: organization ?? defaultOrganization,
|
||||
const loginSettings = await getLoginSettings({ serviceConfig, organization: organization ?? defaultOrganization,
|
||||
});
|
||||
|
||||
return (
|
||||
|
||||
@@ -3,7 +3,7 @@ import { DynamicTheme } from "@/components/dynamic-theme";
|
||||
import { SetPasswordForm } from "@/components/set-password-form";
|
||||
import { Translated } from "@/components/translated";
|
||||
import { UserAvatar } from "@/components/user-avatar";
|
||||
import { getServiceUrlFromHeaders } from "@/lib/service-url";
|
||||
import { getServiceConfig } from "@/lib/service-url";
|
||||
import { loadMostRecentSession } from "@/lib/session";
|
||||
import { getBrandingSettings, getLoginSettings, getPasswordComplexitySettings, getUserByID } from "@/lib/zitadel";
|
||||
import { Session } from "@zitadel/proto/zitadel/session/v2/session_pb";
|
||||
@@ -23,41 +23,31 @@ export default async function Page(props: { searchParams: Promise<Record<string
|
||||
const { userId, loginName, organization, requestId, code, initial } = searchParams;
|
||||
|
||||
const _headers = await headers();
|
||||
const { serviceUrl } = getServiceUrlFromHeaders(_headers);
|
||||
const { serviceConfig } = getServiceConfig(_headers);
|
||||
|
||||
// also allow no session to be found (ignoreUnkownUsername)
|
||||
let session: Session | undefined;
|
||||
if (loginName) {
|
||||
session = await loadMostRecentSession({
|
||||
serviceUrl,
|
||||
sessionParams: {
|
||||
session = await loadMostRecentSession({ serviceConfig, sessionParams: {
|
||||
loginName,
|
||||
organization,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
const branding = await getBrandingSettings({
|
||||
serviceUrl,
|
||||
organization,
|
||||
const branding = await getBrandingSettings({ serviceConfig, organization,
|
||||
});
|
||||
|
||||
const passwordComplexity = await getPasswordComplexitySettings({
|
||||
serviceUrl,
|
||||
organization: session?.factors?.user?.organizationId,
|
||||
const passwordComplexity = await getPasswordComplexitySettings({ serviceConfig, organization: session?.factors?.user?.organizationId,
|
||||
});
|
||||
|
||||
const loginSettings = await getLoginSettings({
|
||||
serviceUrl,
|
||||
organization,
|
||||
const loginSettings = await getLoginSettings({ serviceConfig, organization,
|
||||
});
|
||||
|
||||
let user: User | undefined;
|
||||
let displayName: string | undefined;
|
||||
if (userId) {
|
||||
const userResponse = await getUserByID({
|
||||
serviceUrl,
|
||||
userId,
|
||||
const userResponse = await getUserByID({ serviceConfig, userId,
|
||||
});
|
||||
user = userResponse.user;
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ import { DynamicTheme } from "@/components/dynamic-theme";
|
||||
import { RegisterForm } from "@/components/register-form";
|
||||
import { SignInWithIdp } from "@/components/sign-in-with-idp";
|
||||
import { Translated } from "@/components/translated";
|
||||
import { getServiceUrlFromHeaders } from "@/lib/service-url";
|
||||
import { getServiceConfig } from "@/lib/service-url";
|
||||
import {
|
||||
getActiveIdentityProviders,
|
||||
getBrandingSettings,
|
||||
@@ -29,39 +29,27 @@ export default async function Page(props: { searchParams: Promise<Record<string
|
||||
let { firstname, lastname, email, organization, requestId } = searchParams;
|
||||
|
||||
const _headers = await headers();
|
||||
const { serviceUrl } = getServiceUrlFromHeaders(_headers);
|
||||
const { serviceConfig } = getServiceConfig(_headers);
|
||||
|
||||
if (!organization) {
|
||||
const org: Organization | null = await getDefaultOrg({
|
||||
serviceUrl,
|
||||
});
|
||||
const org: Organization | null = await getDefaultOrg({ serviceConfig, });
|
||||
if (org) {
|
||||
organization = org.id;
|
||||
}
|
||||
}
|
||||
|
||||
const legal = await getLegalAndSupportSettings({
|
||||
serviceUrl,
|
||||
organization,
|
||||
const legal = await getLegalAndSupportSettings({ serviceConfig, organization,
|
||||
});
|
||||
const passwordComplexitySettings = await getPasswordComplexitySettings({
|
||||
serviceUrl,
|
||||
organization,
|
||||
const passwordComplexitySettings = await getPasswordComplexitySettings({ serviceConfig, organization,
|
||||
});
|
||||
|
||||
const branding = await getBrandingSettings({
|
||||
serviceUrl,
|
||||
organization,
|
||||
const branding = await getBrandingSettings({ serviceConfig, organization,
|
||||
});
|
||||
|
||||
const loginSettings = await getLoginSettings({
|
||||
serviceUrl,
|
||||
organization,
|
||||
const loginSettings = await getLoginSettings({ serviceConfig, organization,
|
||||
});
|
||||
|
||||
const identityProviders = await getActiveIdentityProviders({
|
||||
serviceUrl,
|
||||
orgId: organization,
|
||||
const identityProviders = await getActiveIdentityProviders({ serviceConfig, orgId: organization,
|
||||
}).then((resp) => {
|
||||
return resp.identityProviders.filter((idp) => {
|
||||
return idp.options?.isAutoCreation || idp.options?.isCreationAllowed; // check if IDP allows to create account automatically or manual creation is allowed
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { DynamicTheme } from "@/components/dynamic-theme";
|
||||
import { SetRegisterPasswordForm } from "@/components/set-register-password-form";
|
||||
import { Translated } from "@/components/translated";
|
||||
import { getServiceUrlFromHeaders } from "@/lib/service-url";
|
||||
import { getServiceConfig } from "@/lib/service-url";
|
||||
import {
|
||||
getBrandingSettings,
|
||||
getDefaultOrg,
|
||||
@@ -18,12 +18,10 @@ export default async function Page(props: { searchParams: Promise<Record<string
|
||||
let { firstname, lastname, email, organization, requestId } = searchParams;
|
||||
|
||||
const _headers = await headers();
|
||||
const { serviceUrl } = getServiceUrlFromHeaders(_headers);
|
||||
const { serviceConfig } = getServiceConfig(_headers);
|
||||
|
||||
if (!organization) {
|
||||
const org: Organization | null = await getDefaultOrg({
|
||||
serviceUrl,
|
||||
});
|
||||
const org: Organization | null = await getDefaultOrg({ serviceConfig, });
|
||||
if (org) {
|
||||
organization = org.id;
|
||||
}
|
||||
@@ -31,23 +29,15 @@ export default async function Page(props: { searchParams: Promise<Record<string
|
||||
|
||||
const missingData = !firstname || !lastname || !email || !organization;
|
||||
|
||||
const legal = await getLegalAndSupportSettings({
|
||||
serviceUrl,
|
||||
organization,
|
||||
const legal = await getLegalAndSupportSettings({ serviceConfig, organization,
|
||||
});
|
||||
const passwordComplexitySettings = await getPasswordComplexitySettings({
|
||||
serviceUrl,
|
||||
organization,
|
||||
const passwordComplexitySettings = await getPasswordComplexitySettings({ serviceConfig, organization,
|
||||
});
|
||||
|
||||
const branding = await getBrandingSettings({
|
||||
serviceUrl,
|
||||
organization,
|
||||
const branding = await getBrandingSettings({ serviceConfig, organization,
|
||||
});
|
||||
|
||||
const loginSettings = await getLoginSettings({
|
||||
serviceUrl,
|
||||
organization,
|
||||
const loginSettings = await getLoginSettings({ serviceConfig, organization,
|
||||
});
|
||||
|
||||
return missingData ? (
|
||||
|
||||
@@ -5,9 +5,9 @@ import { Translated } from "@/components/translated";
|
||||
import { UserAvatar } from "@/components/user-avatar";
|
||||
import { getMostRecentCookieWithLoginname, getSessionCookieById } from "@/lib/cookies";
|
||||
import { completeDeviceAuthorization } from "@/lib/server/device";
|
||||
import { getServiceUrlFromHeaders } from "@/lib/service-url";
|
||||
import { getServiceConfig } from "@/lib/service-url";
|
||||
import { loadMostRecentSession } from "@/lib/session";
|
||||
import { getBrandingSettings, getLoginSettings, getSession } from "@/lib/zitadel";
|
||||
import { getBrandingSettings, getLoginSettings, getSession, ServiceConfig } from "@/lib/zitadel";
|
||||
import { Metadata } from "next";
|
||||
import { getTranslations } from "next-intl/server";
|
||||
import { headers } from "next/headers";
|
||||
@@ -18,11 +18,9 @@ export async function generateMetadata(): Promise<Metadata> {
|
||||
return { title: t("title", { user: "" }) };
|
||||
}
|
||||
|
||||
async function loadSessionById(serviceUrl: string, sessionId: string, organization?: string) {
|
||||
async function loadSessionById(serviceConfig: ServiceConfig, sessionId: string, organization?: string) {
|
||||
const recent = await getSessionCookieById({ sessionId, organization });
|
||||
return getSession({
|
||||
serviceUrl,
|
||||
sessionId: recent.id,
|
||||
return getSession({ serviceConfig, sessionId: recent.id,
|
||||
sessionToken: recent.token,
|
||||
}).then((response) => {
|
||||
if (response?.session) {
|
||||
@@ -35,13 +33,11 @@ export default async function Page(props: { searchParams: Promise<any> }) {
|
||||
const searchParams = await props.searchParams;
|
||||
|
||||
const _headers = await headers();
|
||||
const { serviceUrl } = getServiceUrlFromHeaders(_headers);
|
||||
const { serviceConfig } = getServiceConfig(_headers);
|
||||
|
||||
const { loginName, requestId, organization, sessionId } = searchParams;
|
||||
|
||||
const branding = await getBrandingSettings({
|
||||
serviceUrl,
|
||||
organization,
|
||||
const branding = await getBrandingSettings({ serviceConfig, organization,
|
||||
});
|
||||
|
||||
// complete device authorization flow if device requestId is present
|
||||
@@ -75,17 +71,13 @@ export default async function Page(props: { searchParams: Promise<any> }) {
|
||||
}
|
||||
|
||||
const sessionFactors = sessionId
|
||||
? await loadSessionById(serviceUrl, sessionId, organization)
|
||||
: await loadMostRecentSession({
|
||||
serviceUrl,
|
||||
sessionParams: { loginName, organization },
|
||||
? await loadSessionById(serviceConfig, sessionId, organization)
|
||||
: await loadMostRecentSession({ serviceConfig, sessionParams: { loginName, organization },
|
||||
});
|
||||
|
||||
let loginSettings;
|
||||
if (!requestId) {
|
||||
loginSettings = await getLoginSettings({
|
||||
serviceUrl,
|
||||
organization,
|
||||
loginSettings = await getLoginSettings({ serviceConfig, organization,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import { LoginPasskey } from "@/components/login-passkey";
|
||||
import { Translated } from "@/components/translated";
|
||||
import { UserAvatar } from "@/components/user-avatar";
|
||||
import { getSessionCookieById } from "@/lib/cookies";
|
||||
import { getServiceUrlFromHeaders } from "@/lib/service-url";
|
||||
import { getServiceConfig } from "@/lib/service-url";
|
||||
import { loadMostRecentSession } from "@/lib/session";
|
||||
import { getBrandingSettings, getSession } from "@/lib/zitadel";
|
||||
import { Metadata } from "next";
|
||||
@@ -22,25 +22,19 @@ export default async function Page(props: { searchParams: Promise<Record<string
|
||||
const { loginName, requestId, sessionId, organization } = searchParams;
|
||||
|
||||
const _headers = await headers();
|
||||
const { serviceUrl } = getServiceUrlFromHeaders(_headers);
|
||||
const { serviceConfig } = getServiceConfig(_headers);
|
||||
|
||||
const branding = await getBrandingSettings({
|
||||
serviceUrl,
|
||||
organization,
|
||||
const branding = await getBrandingSettings({ serviceConfig, organization,
|
||||
});
|
||||
|
||||
const sessionFactors = sessionId
|
||||
? await loadSessionById(sessionId, organization)
|
||||
: await loadMostRecentSession({
|
||||
serviceUrl,
|
||||
sessionParams: { loginName, organization },
|
||||
: await loadMostRecentSession({ serviceConfig, sessionParams: { loginName, organization },
|
||||
});
|
||||
|
||||
async function loadSessionById(sessionId: string, organization?: string) {
|
||||
const recent = await getSessionCookieById({ sessionId, organization });
|
||||
return getSession({
|
||||
serviceUrl,
|
||||
sessionId: recent.id,
|
||||
return getSession({ serviceConfig, sessionId: recent.id,
|
||||
sessionToken: recent.token,
|
||||
}).then((response) => {
|
||||
if (response?.session) {
|
||||
|
||||
@@ -3,7 +3,7 @@ import { DynamicTheme } from "@/components/dynamic-theme";
|
||||
import { RegisterU2f } from "@/components/register-u2f";
|
||||
import { Translated } from "@/components/translated";
|
||||
import { UserAvatar } from "@/components/user-avatar";
|
||||
import { getServiceUrlFromHeaders } from "@/lib/service-url";
|
||||
import { getServiceConfig } from "@/lib/service-url";
|
||||
import { loadMostRecentSession } from "@/lib/session";
|
||||
import { getBrandingSettings } from "@/lib/zitadel";
|
||||
import { Metadata } from "next";
|
||||
@@ -21,19 +21,15 @@ export default async function Page(props: { searchParams: Promise<Record<string
|
||||
const { loginName, organization, requestId, checkAfter } = searchParams;
|
||||
|
||||
const _headers = await headers();
|
||||
const { serviceUrl } = getServiceUrlFromHeaders(_headers);
|
||||
const { serviceConfig } = getServiceConfig(_headers);
|
||||
|
||||
const sessionFactors = await loadMostRecentSession({
|
||||
serviceUrl,
|
||||
sessionParams: {
|
||||
const sessionFactors = await loadMostRecentSession({ serviceConfig, sessionParams: {
|
||||
loginName,
|
||||
organization,
|
||||
},
|
||||
});
|
||||
|
||||
const branding = await getBrandingSettings({
|
||||
serviceUrl,
|
||||
organization,
|
||||
const branding = await getBrandingSettings({ serviceConfig, organization,
|
||||
});
|
||||
|
||||
return (
|
||||
|
||||
@@ -3,9 +3,9 @@ import { DynamicTheme } from "@/components/dynamic-theme";
|
||||
import { Translated } from "@/components/translated";
|
||||
import { UserAvatar } from "@/components/user-avatar";
|
||||
import { VerifyForm } from "@/components/verify-form";
|
||||
import { getPublicHostWithProtocol } from "@/lib/server/host";
|
||||
import { sendEmailCode, sendInviteEmailCode } from "@/lib/server/verify";
|
||||
import { getOriginalHostWithProtocol } from "@/lib/server/host";
|
||||
import { getServiceUrlFromHeaders } from "@/lib/service-url";
|
||||
import { getServiceConfig } from "@/lib/service-url";
|
||||
import { loadMostRecentSession } from "@/lib/session";
|
||||
import { getBrandingSettings, getUserByID } from "@/lib/zitadel";
|
||||
import { HumanUser, User } from "@zitadel/proto/zitadel/user/v2/user_pb";
|
||||
@@ -24,12 +24,9 @@ export default async function Page(props: { searchParams: Promise<any> }) {
|
||||
const { userId, loginName, code, organization, requestId, invite, send } = searchParams;
|
||||
|
||||
const _headers = await headers();
|
||||
const { serviceUrl } = getServiceUrlFromHeaders(_headers);
|
||||
const { serviceConfig } = getServiceConfig(_headers);
|
||||
|
||||
const branding = await getBrandingSettings({
|
||||
serviceUrl,
|
||||
organization,
|
||||
});
|
||||
const branding = await getBrandingSettings({ serviceConfig, organization });
|
||||
|
||||
let sessionFactors;
|
||||
let user: User | undefined;
|
||||
@@ -43,7 +40,7 @@ export default async function Page(props: { searchParams: Promise<any> }) {
|
||||
const basePath = process.env.NEXT_PUBLIC_BASE_PATH ?? "";
|
||||
|
||||
async function sendEmail(userId: string) {
|
||||
const hostWithProtocol = await getOriginalHostWithProtocol();
|
||||
const hostWithProtocol = await getPublicHostWithProtocol(_headers);
|
||||
|
||||
if (invite === "true") {
|
||||
await sendInviteEmailCode({
|
||||
@@ -70,7 +67,7 @@ export default async function Page(props: { searchParams: Promise<any> }) {
|
||||
|
||||
if ("loginName" in searchParams) {
|
||||
sessionFactors = await loadMostRecentSession({
|
||||
serviceUrl,
|
||||
serviceConfig,
|
||||
sessionParams: {
|
||||
loginName,
|
||||
organization,
|
||||
@@ -85,10 +82,7 @@ export default async function Page(props: { searchParams: Promise<any> }) {
|
||||
await sendEmail(userId);
|
||||
}
|
||||
|
||||
const userResponse = await getUserByID({
|
||||
serviceUrl,
|
||||
userId,
|
||||
});
|
||||
const userResponse = await getUserByID({ serviceConfig, userId });
|
||||
if (userResponse) {
|
||||
user = userResponse.user;
|
||||
if (user?.type.case === "human") {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { DynamicTheme } from "@/components/dynamic-theme";
|
||||
import { Translated } from "@/components/translated";
|
||||
import { UserAvatar } from "@/components/user-avatar";
|
||||
import { getServiceUrlFromHeaders } from "@/lib/service-url";
|
||||
import { getServiceConfig } from "@/lib/service-url";
|
||||
import { loadMostRecentSession } from "@/lib/session";
|
||||
import { getBrandingSettings, getUserByID } from "@/lib/zitadel";
|
||||
import { HumanUser, User } from "@zitadel/proto/zitadel/user/v2/user_pb";
|
||||
@@ -11,18 +11,14 @@ export default async function Page(props: { searchParams: Promise<any> }) {
|
||||
const searchParams = await props.searchParams;
|
||||
|
||||
const _headers = await headers();
|
||||
const { serviceUrl } = getServiceUrlFromHeaders(_headers);
|
||||
const { serviceConfig } = getServiceConfig(_headers);
|
||||
|
||||
const { loginName, organization, userId } = searchParams;
|
||||
|
||||
const branding = await getBrandingSettings({
|
||||
serviceUrl,
|
||||
organization,
|
||||
const branding = await getBrandingSettings({ serviceConfig, organization,
|
||||
});
|
||||
|
||||
const sessionFactors = await loadMostRecentSession({
|
||||
serviceUrl,
|
||||
sessionParams: { loginName, organization },
|
||||
const sessionFactors = await loadMostRecentSession({ serviceConfig, sessionParams: { loginName, organization },
|
||||
}).catch((error) => {
|
||||
console.warn("Error loading session:", error);
|
||||
});
|
||||
@@ -33,9 +29,7 @@ export default async function Page(props: { searchParams: Promise<any> }) {
|
||||
throw Error("Failed to get user id");
|
||||
}
|
||||
|
||||
const userResponse = await getUserByID({
|
||||
serviceUrl,
|
||||
userId: id,
|
||||
const userResponse = await getUserByID({ serviceConfig, userId: id,
|
||||
});
|
||||
|
||||
let user: User | undefined;
|
||||
|
||||
Reference in New Issue
Block a user