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