mirror of
https://github.com/zitadel/zitadel.git
synced 2025-12-12 07:24:51 +00:00
org primary domain scope
This commit is contained in:
@@ -1,11 +1,12 @@
|
|||||||
import {
|
import {
|
||||||
createCallback,
|
createCallback,
|
||||||
getAuthRequest,
|
getAuthRequest,
|
||||||
|
getOrgByDomain,
|
||||||
listSessions,
|
listSessions,
|
||||||
server,
|
server,
|
||||||
} from "#/lib/zitadel";
|
} from "#/lib/zitadel";
|
||||||
import { SessionCookie, getAllSessions } from "#/utils/cookies";
|
import { SessionCookie, getAllSessions } from "#/utils/cookies";
|
||||||
import { Session, AuthRequest, Prompt, login } from "@zitadel/server";
|
import { Session, AuthRequest, Prompt } from "@zitadel/server";
|
||||||
import { NextRequest, NextResponse } from "next/server";
|
import { NextRequest, NextResponse } from "next/server";
|
||||||
|
|
||||||
async function loadSessions(ids: string[]): Promise<Session[]> {
|
async function loadSessions(ids: string[]): Promise<Session[]> {
|
||||||
@@ -18,6 +19,7 @@ async function loadSessions(ids: string[]): Promise<Session[]> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const ORG_SCOPE_REGEX = /urn:zitadel:iam:org:id:([0-9]+)/;
|
const ORG_SCOPE_REGEX = /urn:zitadel:iam:org:id:([0-9]+)/;
|
||||||
|
const ORG_DOMAIN_SCOPE_REGEX = /urn:zitadel:iam:org:domain:primary:(.+)/; // TODO: check regex for all domain character options
|
||||||
|
|
||||||
function findSession(
|
function findSession(
|
||||||
sessions: Session[],
|
sessions: Session[],
|
||||||
@@ -91,13 +93,26 @@ export async function GET(request: NextRequest) {
|
|||||||
authRequest?.scope &&
|
authRequest?.scope &&
|
||||||
authRequest.scope.find((s: string) => ORG_SCOPE_REGEX.test(s))
|
authRequest.scope.find((s: string) => ORG_SCOPE_REGEX.test(s))
|
||||||
) {
|
) {
|
||||||
const orgId = authRequest.scope.find((s: string) =>
|
const orgScope = authRequest.scope.find((s: string) =>
|
||||||
ORG_SCOPE_REGEX.test(s)
|
ORG_SCOPE_REGEX.test(s)
|
||||||
);
|
);
|
||||||
|
|
||||||
if (orgId) {
|
if (orgScope) {
|
||||||
const matched = ORG_SCOPE_REGEX.exec(orgId);
|
const matched = ORG_SCOPE_REGEX.exec(orgScope);
|
||||||
organization = matched?.[1] ?? "";
|
organization = matched?.[1] ?? "";
|
||||||
|
} else {
|
||||||
|
const orgDomainScope = authRequest.scope.find((s: string) =>
|
||||||
|
ORG_DOMAIN_SCOPE_REGEX.test(s)
|
||||||
|
);
|
||||||
|
|
||||||
|
if (orgDomainScope) {
|
||||||
|
const matched = ORG_DOMAIN_SCOPE_REGEX.exec(orgDomainScope);
|
||||||
|
const orgDomain = matched?.[1] ?? "";
|
||||||
|
if (orgDomain) {
|
||||||
|
const org = await getOrgByDomain(orgDomain);
|
||||||
|
organization = org?.org?.id ?? "";
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,10 +22,11 @@ import {
|
|||||||
SetSessionResponse,
|
SetSessionResponse,
|
||||||
SetSessionRequest,
|
SetSessionRequest,
|
||||||
ListUsersResponse,
|
ListUsersResponse,
|
||||||
ListUsersRequest,
|
management,
|
||||||
DeleteSessionResponse,
|
DeleteSessionResponse,
|
||||||
VerifyPasskeyRegistrationResponse,
|
VerifyPasskeyRegistrationResponse,
|
||||||
LoginSettings,
|
LoginSettings,
|
||||||
|
GetOrgByDomainGlobalResponse,
|
||||||
GetLoginSettingsResponse,
|
GetLoginSettingsResponse,
|
||||||
ListAuthenticationMethodTypesResponse,
|
ListAuthenticationMethodTypesResponse,
|
||||||
StartIdentityProviderIntentRequest,
|
StartIdentityProviderIntentRequest,
|
||||||
@@ -331,6 +332,13 @@ export async function listUsers(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function getOrgByDomain(
|
||||||
|
domain: string
|
||||||
|
): Promise<GetOrgByDomainGlobalResponse> {
|
||||||
|
const mgmtService = management.getManagement(server);
|
||||||
|
return mgmtService.getOrgByDomainGlobal({ domain }, {});
|
||||||
|
}
|
||||||
|
|
||||||
export async function startIdentityProviderFlow(
|
export async function startIdentityProviderFlow(
|
||||||
server: ZitadelServer,
|
server: ZitadelServer,
|
||||||
{ idpId, urls }: StartIdentityProviderIntentRequest
|
{ idpId, urls }: StartIdentityProviderIntentRequest
|
||||||
|
|||||||
@@ -87,6 +87,7 @@ export {
|
|||||||
export {
|
export {
|
||||||
SetHumanPasswordResponse,
|
SetHumanPasswordResponse,
|
||||||
SetHumanPasswordRequest,
|
SetHumanPasswordRequest,
|
||||||
|
GetOrgByDomainGlobalResponse,
|
||||||
} from "./proto/server/zitadel/management";
|
} from "./proto/server/zitadel/management";
|
||||||
export * from "./proto/server/zitadel/idp";
|
export * from "./proto/server/zitadel/idp";
|
||||||
export { type LegalAndSupportSettings } from "./proto/server/zitadel/settings/v2beta/legal_settings";
|
export { type LegalAndSupportSettings } from "./proto/server/zitadel/settings/v2beta/legal_settings";
|
||||||
|
|||||||
Reference in New Issue
Block a user