mirror of
https://github.com/zitadel/zitadel.git
synced 2025-12-12 10:15:04 +00:00
command adr
This commit is contained in:
@@ -8,8 +8,7 @@ type VerifyUserByEmailCommand = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export async function verifyUserByEmail(command: VerifyUserByEmailCommand) {
|
export async function verifyUserByEmail(command: VerifyUserByEmailCommand) {
|
||||||
const { userId, code } = command;
|
return verifyEmail(command.userId, command.code);
|
||||||
return verifyEmail(userId, code);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type resendVerifyEmailCommand = {
|
type resendVerifyEmailCommand = {
|
||||||
@@ -17,8 +16,5 @@ type resendVerifyEmailCommand = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export async function resendVerifyEmail(command: resendVerifyEmailCommand) {
|
export async function resendVerifyEmail(command: resendVerifyEmailCommand) {
|
||||||
const { userId } = command;
|
return resendEmailCode(command.userId);
|
||||||
|
|
||||||
// replace with resend Mail method once its implemented
|
|
||||||
return resendEmailCode(userId);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,13 +9,11 @@ export type StartIDPFlowCommand = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export async function startIDPFlow(command: StartIDPFlowCommand) {
|
export async function startIDPFlow(command: StartIDPFlowCommand) {
|
||||||
const { idpId, successUrl, failureUrl } = command;
|
|
||||||
|
|
||||||
return startIdentityProviderFlow({
|
return startIdentityProviderFlow({
|
||||||
idpId,
|
idpId: command.idpId,
|
||||||
urls: {
|
urls: {
|
||||||
successUrl,
|
successUrl: command.successUrl,
|
||||||
failureUrl,
|
failureUrl: command.failureUrl,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,11 +18,10 @@ export type SendLoginnameCommand = {
|
|||||||
organization?: string;
|
organization?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export async function sendLoginname(options: SendLoginnameCommand) {
|
export async function sendLoginname(command: SendLoginnameCommand) {
|
||||||
const { loginName, authRequestId, organization } = options;
|
|
||||||
const users = await listUsers({
|
const users = await listUsers({
|
||||||
userName: loginName,
|
userName: command.loginName,
|
||||||
organizationId: organization,
|
organizationId: command.organization,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (users.details?.totalResult == BigInt(1) && users.result[0].userId) {
|
if (users.details?.totalResult == BigInt(1) && users.result[0].userId) {
|
||||||
@@ -31,7 +30,7 @@ export async function sendLoginname(options: SendLoginnameCommand) {
|
|||||||
userId,
|
userId,
|
||||||
undefined,
|
undefined,
|
||||||
undefined,
|
undefined,
|
||||||
authRequestId,
|
command.authRequestId,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!session.factors?.user?.id) {
|
if (!session.factors?.user?.id) {
|
||||||
@@ -49,14 +48,14 @@ export async function sendLoginname(options: SendLoginnameCommand) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const loginSettings = await getLoginSettings(organization);
|
const loginSettings = await getLoginSettings(command.organization);
|
||||||
// TODO: check if allowDomainDiscovery has to be allowed too, to redirect to the register page
|
// TODO: check if allowDomainDiscovery has to be allowed too, to redirect to the register page
|
||||||
// user not found, check if register is enabled on organization
|
// user not found, check if register is enabled on organization
|
||||||
|
|
||||||
if (loginSettings?.allowRegister && !loginSettings?.allowUsernamePassword) {
|
if (loginSettings?.allowRegister && !loginSettings?.allowUsernamePassword) {
|
||||||
// TODO redirect to loginname page with idp hint
|
// TODO redirect to loginname page with idp hint
|
||||||
const identityProviders = await getActiveIdentityProviders(
|
const identityProviders = await getActiveIdentityProviders(
|
||||||
organization,
|
command.organization,
|
||||||
).then((resp) => {
|
).then((resp) => {
|
||||||
return resp.identityProviders;
|
return resp.identityProviders;
|
||||||
});
|
});
|
||||||
@@ -70,12 +69,12 @@ export async function sendLoginname(options: SendLoginnameCommand) {
|
|||||||
|
|
||||||
const params = new URLSearchParams();
|
const params = new URLSearchParams();
|
||||||
|
|
||||||
if (authRequestId) {
|
if (command.authRequestId) {
|
||||||
params.set("authRequestId", authRequestId);
|
params.set("authRequestId", command.authRequestId);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (organization) {
|
if (command.organization) {
|
||||||
params.set("organization", organization);
|
params.set("organization", command.organization);
|
||||||
}
|
}
|
||||||
|
|
||||||
return startIdentityProviderFlow({
|
return startIdentityProviderFlow({
|
||||||
@@ -98,18 +97,19 @@ export async function sendLoginname(options: SendLoginnameCommand) {
|
|||||||
loginSettings?.allowRegister &&
|
loginSettings?.allowRegister &&
|
||||||
loginSettings?.allowUsernamePassword
|
loginSettings?.allowUsernamePassword
|
||||||
) {
|
) {
|
||||||
const params: any = { organization };
|
const params = new URLSearchParams();
|
||||||
if (authRequestId) {
|
|
||||||
params.authRequestId = authRequestId;
|
if (command.organization) {
|
||||||
|
params.set("organization", command.organization);
|
||||||
}
|
}
|
||||||
if (loginName) {
|
if (command.authRequestId) {
|
||||||
params.email = loginName;
|
params.set("authRequestId", command.authRequestId);
|
||||||
|
}
|
||||||
|
if (command.loginName) {
|
||||||
|
params.set("loginName", command.loginName);
|
||||||
}
|
}
|
||||||
|
|
||||||
const registerUrl = new URL(
|
const registerUrl = new URL("/register?" + params);
|
||||||
"/register?" + new URLSearchParams(params),
|
|
||||||
// request.url,
|
|
||||||
);
|
|
||||||
|
|
||||||
return redirect(registerUrl.toString());
|
return redirect(registerUrl.toString());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,19 +23,17 @@ export type SetOTPCommand = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export async function setOTP(command: SetOTPCommand) {
|
export async function setOTP(command: SetOTPCommand) {
|
||||||
const { loginName, sessionId, organization, authRequestId, code, method } =
|
const recentPromise = command.sessionId
|
||||||
command;
|
? getSessionCookieById({ sessionId: command.sessionId }).catch((error) => {
|
||||||
|
|
||||||
const recentPromise = sessionId
|
|
||||||
? getSessionCookieById({ sessionId }).catch((error) => {
|
|
||||||
return Promise.reject(error);
|
return Promise.reject(error);
|
||||||
})
|
})
|
||||||
: loginName
|
: command.loginName
|
||||||
? getSessionCookieByLoginName({ loginName, organization }).catch(
|
? getSessionCookieByLoginName({
|
||||||
(error) => {
|
loginName: command.loginName,
|
||||||
return Promise.reject(error);
|
organization: command.organization,
|
||||||
},
|
}).catch((error) => {
|
||||||
)
|
return Promise.reject(error);
|
||||||
|
})
|
||||||
: getMostRecentSessionCookie().catch((error) => {
|
: getMostRecentSessionCookie().catch((error) => {
|
||||||
return Promise.reject(error);
|
return Promise.reject(error);
|
||||||
});
|
});
|
||||||
@@ -43,17 +41,17 @@ export async function setOTP(command: SetOTPCommand) {
|
|||||||
return recentPromise.then((recent) => {
|
return recentPromise.then((recent) => {
|
||||||
const checks = create(ChecksSchema, {});
|
const checks = create(ChecksSchema, {});
|
||||||
|
|
||||||
if (method === "time-based") {
|
if (command.method === "time-based") {
|
||||||
checks.totp = create(CheckTOTPSchema, {
|
checks.totp = create(CheckTOTPSchema, {
|
||||||
code,
|
code: command.code,
|
||||||
});
|
});
|
||||||
} else if (method === "sms") {
|
} else if (command.method === "sms") {
|
||||||
checks.otpSms = create(CheckOTPSchema, {
|
checks.otpSms = create(CheckOTPSchema, {
|
||||||
code,
|
code: command.code,
|
||||||
});
|
});
|
||||||
} else if (method === "email") {
|
} else if (command.method === "email") {
|
||||||
checks.otpEmail = create(CheckOTPSchema, {
|
checks.otpEmail = create(CheckOTPSchema, {
|
||||||
code,
|
code: command.code,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -61,7 +59,7 @@ export async function setOTP(command: SetOTPCommand) {
|
|||||||
recent,
|
recent,
|
||||||
checks,
|
checks,
|
||||||
undefined,
|
undefined,
|
||||||
authRequestId,
|
command.authRequestId,
|
||||||
).then((session) => {
|
).then((session) => {
|
||||||
return {
|
return {
|
||||||
sessionId: session.id,
|
sessionId: session.id,
|
||||||
|
|||||||
@@ -54,9 +54,8 @@ export async function registerPasskeyLink(
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function verifyPasskey(command: VerifyPasskeyCommand) {
|
export async function verifyPasskey(command: VerifyPasskeyCommand) {
|
||||||
let { passkeyId, passkeyName, publicKeyCredential, sessionId } = command;
|
|
||||||
|
|
||||||
// if no name is provided, try to generate one from the user agent
|
// if no name is provided, try to generate one from the user agent
|
||||||
|
let passkeyName = command.passkeyName;
|
||||||
if (!!!passkeyName) {
|
if (!!!passkeyName) {
|
||||||
const headersList = headers();
|
const headersList = headers();
|
||||||
const userAgentStructure = { headers: headersList };
|
const userAgentStructure = { headers: headersList };
|
||||||
@@ -67,7 +66,9 @@ export async function verifyPasskey(command: VerifyPasskeyCommand) {
|
|||||||
}${os.name}${os.name ? ", " : ""}${browser.name}`;
|
}${os.name}${os.name ? ", " : ""}${browser.name}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
const sessionCookie = await getSessionCookieById({ sessionId });
|
const sessionCookie = await getSessionCookieById({
|
||||||
|
sessionId: command.sessionId,
|
||||||
|
});
|
||||||
const session = await getSession(sessionCookie.id, sessionCookie.token);
|
const session = await getSession(sessionCookie.id, sessionCookie.token);
|
||||||
const userId = session?.session?.factors?.user?.id;
|
const userId = session?.session?.factors?.user?.id;
|
||||||
|
|
||||||
@@ -77,9 +78,9 @@ export async function verifyPasskey(command: VerifyPasskeyCommand) {
|
|||||||
|
|
||||||
return verifyPasskeyRegistration(
|
return verifyPasskeyRegistration(
|
||||||
create(VerifyPasskeyRegistrationRequestSchema, {
|
create(VerifyPasskeyRegistrationRequestSchema, {
|
||||||
passkeyId,
|
passkeyId: command.passkeyId,
|
||||||
|
publicKeyCredential: command.publicKeyCredential,
|
||||||
passkeyName,
|
passkeyName,
|
||||||
publicKeyCredential,
|
|
||||||
userId,
|
userId,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -8,10 +8,9 @@ type ResetPasswordCommand = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export async function resetPassword(command: ResetPasswordCommand) {
|
export async function resetPassword(command: ResetPasswordCommand) {
|
||||||
const { loginName, organization } = command;
|
|
||||||
const users = await listUsers({
|
const users = await listUsers({
|
||||||
userName: loginName,
|
userName: command.loginName,
|
||||||
organizationId: organization,
|
organizationId: command.organization,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (
|
if (
|
||||||
|
|||||||
@@ -12,15 +12,12 @@ type RegisterUserCommand = {
|
|||||||
authRequestId?: string;
|
authRequestId?: string;
|
||||||
};
|
};
|
||||||
export async function registerUser(command: RegisterUserCommand) {
|
export async function registerUser(command: RegisterUserCommand) {
|
||||||
const { email, password, firstName, lastName, organization, authRequestId } =
|
|
||||||
command;
|
|
||||||
|
|
||||||
const human = await addHumanUser({
|
const human = await addHumanUser({
|
||||||
email: email,
|
email: command.email,
|
||||||
firstName,
|
firstName: command.firstName,
|
||||||
lastName,
|
lastName: command.lastName,
|
||||||
password: password ? password : undefined,
|
password: command.password ? command.password : undefined,
|
||||||
organization,
|
organization: command.organization,
|
||||||
});
|
});
|
||||||
if (!human) {
|
if (!human) {
|
||||||
throw Error("Could not create user");
|
throw Error("Could not create user");
|
||||||
@@ -28,9 +25,9 @@ export async function registerUser(command: RegisterUserCommand) {
|
|||||||
|
|
||||||
return createSessionForUserIdAndUpdateCookie(
|
return createSessionForUserIdAndUpdateCookie(
|
||||||
human.userId,
|
human.userId,
|
||||||
password,
|
command.password,
|
||||||
undefined,
|
undefined,
|
||||||
authRequestId,
|
command.authRequestId,
|
||||||
).then((session) => {
|
).then((session) => {
|
||||||
return {
|
return {
|
||||||
userId: human.userId,
|
userId: human.userId,
|
||||||
|
|||||||
@@ -19,9 +19,9 @@ type VerifyU2FCommand = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export async function addU2F(command: RegisterU2FCommand) {
|
export async function addU2F(command: RegisterU2FCommand) {
|
||||||
const { sessionId } = command;
|
const sessionCookie = await getSessionCookieById({
|
||||||
|
sessionId: command.sessionId,
|
||||||
const sessionCookie = await getSessionCookieById({ sessionId });
|
});
|
||||||
|
|
||||||
const session = await getSession(sessionCookie.id, sessionCookie.token);
|
const session = await getSession(sessionCookie.id, sessionCookie.token);
|
||||||
|
|
||||||
@@ -40,8 +40,7 @@ export async function addU2F(command: RegisterU2FCommand) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function verifyU2F(command: VerifyU2FCommand) {
|
export async function verifyU2F(command: VerifyU2FCommand) {
|
||||||
let { passkeyName, sessionId } = command;
|
let passkeyName = command.passkeyName;
|
||||||
|
|
||||||
if (!!!passkeyName) {
|
if (!!!passkeyName) {
|
||||||
const headersList = headers();
|
const headersList = headers();
|
||||||
const userAgentStructure = { headers: headersList };
|
const userAgentStructure = { headers: headersList };
|
||||||
@@ -51,7 +50,9 @@ export async function verifyU2F(command: VerifyU2FCommand) {
|
|||||||
device.vendor || device.model ? ", " : ""
|
device.vendor || device.model ? ", " : ""
|
||||||
}${os.name}${os.name ? ", " : ""}${browser.name}`;
|
}${os.name}${os.name ? ", " : ""}${browser.name}`;
|
||||||
}
|
}
|
||||||
const sessionCookie = await getSessionCookieById({ sessionId });
|
const sessionCookie = await getSessionCookieById({
|
||||||
|
sessionId: command.sessionId,
|
||||||
|
});
|
||||||
|
|
||||||
const session = await getSession(sessionCookie.id, sessionCookie.token);
|
const session = await getSession(sessionCookie.id, sessionCookie.token);
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import {
|
|||||||
makeReqCtx,
|
makeReqCtx,
|
||||||
createOrganizationServiceClient,
|
createOrganizationServiceClient,
|
||||||
} from "@zitadel/client/v2";
|
} from "@zitadel/client/v2";
|
||||||
import { createManagementServiceClient } from "@zitadel/client/v1";
|
|
||||||
import { createServerTransport } from "@zitadel/node";
|
import { createServerTransport } from "@zitadel/node";
|
||||||
import { Checks } from "@zitadel/proto/zitadel/session/v2/session_service_pb";
|
import { Checks } from "@zitadel/proto/zitadel/session/v2/session_service_pb";
|
||||||
import { RequestChallenges } from "@zitadel/proto/zitadel/session/v2/challenge_pb";
|
import { RequestChallenges } from "@zitadel/proto/zitadel/session/v2/challenge_pb";
|
||||||
|
|||||||
Reference in New Issue
Block a user