mirror of
https://github.com/zitadel/zitadel.git
synced 2025-12-12 18:12:22 +00:00
set mfa page, auth service
This commit is contained in:
@@ -5,25 +5,43 @@ import {
|
||||
AuthServiceDefinition,
|
||||
GetMyUserResponse,
|
||||
} from "../proto/server/zitadel/auth";
|
||||
import { ZitadelServer } from "../server";
|
||||
import { ZitadelServer, getServers } from "../server";
|
||||
import { authMiddleware } from "../middleware";
|
||||
|
||||
const createClient = <Client>(
|
||||
definition: CompatServiceDefinition,
|
||||
accessToken: string
|
||||
apiUrl: string,
|
||||
token: string
|
||||
) => {
|
||||
if (!apiUrl) {
|
||||
throw Error("ZITADEL_API_URL not set");
|
||||
}
|
||||
|
||||
const channel = createChannel(process.env.ZITADEL_API_URL ?? "");
|
||||
return createClientFactory()
|
||||
.use(authMiddleware(accessToken))
|
||||
.use(authMiddleware(token))
|
||||
.create(definition, channel) as Client;
|
||||
};
|
||||
|
||||
export async function getAuth(app?: ZitadelServer): Promise<AuthServiceClient> {
|
||||
export const getAuth = (app?: string | ZitadelServer) => {
|
||||
let config;
|
||||
if (app && typeof app === "string") {
|
||||
const apps = getServers();
|
||||
config = apps.find((a) => a.name === app)?.config;
|
||||
} else if (app && typeof app === "object") {
|
||||
config = app.config;
|
||||
}
|
||||
|
||||
if (!config) {
|
||||
throw Error("No ZITADEL app found");
|
||||
}
|
||||
|
||||
return createClient<AuthServiceClient>(
|
||||
AuthServiceDefinition as CompatServiceDefinition,
|
||||
""
|
||||
config.apiUrl,
|
||||
config.token
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
export async function getMyUser(): Promise<GetMyUserResponse> {
|
||||
const auth = await getAuth();
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
export * from "../proto/server/zitadel/auth";
|
||||
export { getAuth } from "./auth";
|
||||
export * from "./auth";
|
||||
export * as auth from "../proto/server/zitadel/auth";
|
||||
|
||||
@@ -3,6 +3,7 @@ import * as session from "./v2/session";
|
||||
import * as user from "./v2/user";
|
||||
import * as oidc from "./v2/oidc";
|
||||
import * as management from "./management";
|
||||
import * as auth from "./auth";
|
||||
|
||||
import * as login from "./proto/server/zitadel/settings/v2beta/login_settings";
|
||||
import * as password from "./proto/server/zitadel/settings/v2beta/password_settings";
|
||||
@@ -96,7 +97,10 @@ export * from "./proto/server/zitadel/idp";
|
||||
export { type LegalAndSupportSettings } from "./proto/server/zitadel/settings/v2beta/legal_settings";
|
||||
export { type PasswordComplexitySettings } from "./proto/server/zitadel/settings/v2beta/password_settings";
|
||||
export { type ResourceOwnerType } from "./proto/server/zitadel/settings/v2beta/settings";
|
||||
|
||||
export {
|
||||
type VerifyMyAuthFactorOTPResponse,
|
||||
AddMyAuthFactorOTPResponse,
|
||||
} from "./proto/server/zitadel/auth";
|
||||
import {
|
||||
getServers,
|
||||
initializeServer,
|
||||
@@ -118,4 +122,5 @@ export {
|
||||
password,
|
||||
legal,
|
||||
oidc,
|
||||
auth,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user