mirror of
https://github.com/zitadel/zitadel.git
synced 2025-12-11 22:22:31 +00:00
Merge branch 'main' into buf-v2-breakingchanges
This commit is contained in:
@@ -2,6 +2,7 @@ import { idpTypeToSlug } from "@/lib/idp";
|
|||||||
import {
|
import {
|
||||||
getActiveIdentityProviders,
|
getActiveIdentityProviders,
|
||||||
getLoginSettings,
|
getLoginSettings,
|
||||||
|
getOrgsByDomain,
|
||||||
listAuthenticationMethodTypes,
|
listAuthenticationMethodTypes,
|
||||||
listUsers,
|
listUsers,
|
||||||
startIdentityProviderFlow,
|
startIdentityProviderFlow,
|
||||||
@@ -9,6 +10,8 @@ import {
|
|||||||
import { createSessionForUserIdAndUpdateCookie } from "@/utils/session";
|
import { createSessionForUserIdAndUpdateCookie } from "@/utils/session";
|
||||||
import { NextRequest, NextResponse } from "next/server";
|
import { NextRequest, NextResponse } from "next/server";
|
||||||
|
|
||||||
|
const ORG_SUFFIX_REGEX = /(?<=@)(.+)/;
|
||||||
|
|
||||||
export async function POST(request: NextRequest) {
|
export async function POST(request: NextRequest) {
|
||||||
const body = await request.json();
|
const body = await request.json();
|
||||||
if (body) {
|
if (body) {
|
||||||
@@ -104,14 +107,45 @@ export async function POST(request: NextRequest) {
|
|||||||
loginSettings?.allowRegister &&
|
loginSettings?.allowRegister &&
|
||||||
loginSettings?.allowUsernamePassword
|
loginSettings?.allowUsernamePassword
|
||||||
) {
|
) {
|
||||||
const params: any = { organization };
|
let orgToRegisterOn: string | undefined = organization;
|
||||||
|
|
||||||
|
if (
|
||||||
|
!orgToRegisterOn &&
|
||||||
|
loginName &&
|
||||||
|
ORG_SUFFIX_REGEX.test(loginName)
|
||||||
|
) {
|
||||||
|
const matched = ORG_SUFFIX_REGEX.exec(loginName);
|
||||||
|
const suffix = matched?.[1] ?? "";
|
||||||
|
|
||||||
|
// this just returns orgs where the suffix is set as primary domain
|
||||||
|
const orgs = await getOrgsByDomain(suffix);
|
||||||
|
const orgToCheckForDiscovery =
|
||||||
|
orgs.result && orgs.result.length === 1
|
||||||
|
? orgs.result[0].id
|
||||||
|
: undefined;
|
||||||
|
|
||||||
|
const orgLoginSettings = await getLoginSettings(
|
||||||
|
orgToCheckForDiscovery,
|
||||||
|
);
|
||||||
|
if (orgLoginSettings?.allowDomainDiscovery) {
|
||||||
|
orgToRegisterOn = orgToCheckForDiscovery;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const params: any = {};
|
||||||
|
|
||||||
if (authRequestId) {
|
if (authRequestId) {
|
||||||
params.authRequestId = authRequestId;
|
params.authRequestId = authRequestId;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (loginName) {
|
if (loginName) {
|
||||||
params.email = loginName;
|
params.email = loginName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (orgToRegisterOn) {
|
||||||
|
params.organization = orgToRegisterOn;
|
||||||
|
}
|
||||||
|
|
||||||
const registerUrl = new URL(
|
const registerUrl = new URL(
|
||||||
"/register?" + new URLSearchParams(params),
|
"/register?" + new URLSearchParams(params),
|
||||||
request.url,
|
request.url,
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import {
|
|||||||
createCallback,
|
createCallback,
|
||||||
getActiveIdentityProviders,
|
getActiveIdentityProviders,
|
||||||
getAuthRequest,
|
getAuthRequest,
|
||||||
getOrgByDomain,
|
getOrgsByDomain,
|
||||||
listSessions,
|
listSessions,
|
||||||
startIdentityProviderFlow,
|
startIdentityProviderFlow,
|
||||||
} from "@/lib/zitadel";
|
} from "@/lib/zitadel";
|
||||||
@@ -155,8 +155,10 @@ export async function GET(request: NextRequest) {
|
|||||||
const matched = ORG_DOMAIN_SCOPE_REGEX.exec(orgDomainScope);
|
const matched = ORG_DOMAIN_SCOPE_REGEX.exec(orgDomainScope);
|
||||||
const orgDomain = matched?.[1] ?? "";
|
const orgDomain = matched?.[1] ?? "";
|
||||||
if (orgDomain) {
|
if (orgDomain) {
|
||||||
const org = await getOrgByDomain(orgDomain);
|
const orgs = await getOrgsByDomain(orgDomain);
|
||||||
organization = org?.org?.id ?? "";
|
if (orgs.result && orgs.result.length === 1) {
|
||||||
|
organization = orgs.result[0].id ?? "";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import {
|
|||||||
createUserServiceClient,
|
createUserServiceClient,
|
||||||
createIdpServiceClient,
|
createIdpServiceClient,
|
||||||
makeReqCtx,
|
makeReqCtx,
|
||||||
|
createOrganizationServiceClient,
|
||||||
} from "@zitadel/client/v2";
|
} from "@zitadel/client/v2";
|
||||||
import { createManagementServiceClient } from "@zitadel/client/v1";
|
import { createManagementServiceClient } from "@zitadel/client/v1";
|
||||||
import { createServerTransport } from "@zitadel/node";
|
import { createServerTransport } from "@zitadel/node";
|
||||||
@@ -38,10 +39,10 @@ const transport = createServerTransport(
|
|||||||
);
|
);
|
||||||
|
|
||||||
export const sessionService = createSessionServiceClient(transport);
|
export const sessionService = createSessionServiceClient(transport);
|
||||||
export const managementService = createManagementServiceClient(transport);
|
|
||||||
export const userService = createUserServiceClient(transport);
|
export const userService = createUserServiceClient(transport);
|
||||||
export const oidcService = createOIDCServiceClient(transport);
|
export const oidcService = createOIDCServiceClient(transport);
|
||||||
export const idpService = createIdpServiceClient(transport);
|
export const idpService = createIdpServiceClient(transport);
|
||||||
|
export const orgService = createOrganizationServiceClient(transport);
|
||||||
|
|
||||||
export const settingsService = createSettingsServiceClient(transport);
|
export const settingsService = createSettingsServiceClient(transport);
|
||||||
|
|
||||||
@@ -295,8 +296,20 @@ export async function listUsers({
|
|||||||
return userService.listUsers({ queries: queries });
|
return userService.listUsers({ queries: queries });
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getOrgByDomain(domain: string) {
|
export async function getOrgsByDomain(domain: string) {
|
||||||
return managementService.getOrgByDomainGlobal({ domain }, {});
|
return orgService.listOrganizations(
|
||||||
|
{
|
||||||
|
queries: [
|
||||||
|
{
|
||||||
|
query: {
|
||||||
|
case: "domainQuery",
|
||||||
|
value: { domain, method: TextQueryMethod.EQUALS },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{},
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function startIdentityProviderFlow({
|
export async function startIdentityProviderFlow({
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { UserSchemaService } from "@zitadel/proto/zitadel/user/schema/v3alpha/user_schema_service_pb";
|
import { ZITADELUsers } from "@zitadel/proto/zitadel/resources/user/v3alpha/user_service_connect";
|
||||||
import { UserService } from "@zitadel/proto/zitadel/user/v3alpha/user_service_pb";
|
import { ZITADELUserSchemas } from "@zitadel/proto/zitadel/resources/userschema/v3alpha/user_schema_service_connect";
|
||||||
import { createClientFor } from "./helpers";
|
import { createClientFor } from "./helpers";
|
||||||
|
|
||||||
export const createUserSchemaServiceClient = createClientFor(UserSchemaService);
|
export const createUserSchemaServiceClient = createClientFor(ZITADELUserSchemas);
|
||||||
export const createUserServiceClient = createClientFor(UserService);
|
export const createUserServiceClient = createClientFor(ZITADELUsers);
|
||||||
|
|||||||
Reference in New Issue
Block a user