This commit is contained in:
Max Peintner
2024-11-15 13:48:42 +01:00
parent bdd0357211
commit c9eb18a7bf
17 changed files with 547 additions and 536 deletions

View File

@@ -2,6 +2,6 @@ import {test} from "@playwright/test";
import { loginScreenExpect, loginWithPassword } from "./login";
test("admin login", async ({ page }) => {
await loginWithPassword(page, "zitadel-admin@zitadel.localhost", "Password1.")
await loginWithPassword(page, "zitadel-admin@zitadel.localhost", "Password1.");
await loginScreenExpect(page, "ZITADEL Admin");
});

View File

@@ -19,12 +19,10 @@ export async function loginWithPasskey(page: Page, authenticatorId: string, user
}
export async function loginScreenExpect(page: Page, fullName: string) {
await expect(page).toHaveURL(/signedin.*/)
await expect(page.getByRole('heading')).toContainText(fullName);
await expect(page).toHaveURL(/signedin.*/);
await expect(page.getByRole("heading")).toContainText(fullName);
}
export async function loginWithOTP(page: Page, username: string, password: string) {
await loginWithPassword(page, username, password);
}

View File

@@ -1,6 +1,6 @@
import { expect, Page } from "@playwright/test";
const usernameUserInput = "username-text-input"
const usernameUserInput = "username-text-input";
export async function loginnameScreen(page: Page, username: string) {
await page.getByTestId(usernameUserInput).pressSequentially(username);
@@ -8,5 +8,5 @@ export async function loginnameScreen(page: Page, username: string) {
export async function loginnameScreenExpect(page: Page, username: string) {
await expect(page.getByTestId(usernameUserInput)).toHaveValue(username);
await expect(page.getByTestId('error').locator('div')).toContainText("Could not find user")
await expect(page.getByTestId("error").locator("div")).toContainText("Could not find user");
}

View File

@@ -2,6 +2,6 @@ import {Page} from "@playwright/test";
import { loginnameScreen } from "./loginname-screen";
export async function loginname(page: Page, username: string) {
await loginnameScreen(page, username)
await page.getByTestId("submit-button").click()
await loginnameScreen(page, username);
await page.getByTestId("submit-button").click();
}

View File

@@ -3,23 +3,23 @@ import * as http from "node:http";
let messages = new Map<string, any>();
export function startSink() {
const hostname = "127.0.0.1"
const port = 3030
const hostname = "127.0.0.1";
const port = 3030;
const server = http.createServer((req, res) => {
console.log("Sink received message: ")
let body = '';
req.on('data', (chunk) => {
console.log("Sink received message: ");
let body = "";
req.on("data", (chunk) => {
body += chunk;
});
req.on('end', () => {
req.on("end", () => {
console.log(body);
const data = JSON.parse(body)
messages.set(data.contextInfo.recipientEmailAddress, data.args.code)
const data = JSON.parse(body);
messages.set(data.contextInfo.recipientEmailAddress, data.args.code);
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
res.write('OK');
res.setHeader("Content-Type", "text/plain");
res.write("OK");
res.end();
});
});
@@ -27,5 +27,5 @@ export function startSink() {
server.listen(port, hostname, () => {
console.log(`Sink running at http://${hostname}:${port}/`);
});
return server
return server;
}

View File

@@ -2,17 +2,17 @@ import {expect, Page} from "@playwright/test";
import { CDPSession } from "playwright-core";
interface session {
client: CDPSession
authenticatorId: string
client: CDPSession;
authenticatorId: string;
}
async function client(page: Page): Promise<session> {
const cdpSession = await page.context().newCDPSession(page);
await cdpSession.send('WebAuthn.enable', {enableUI: false});
const result = await cdpSession.send('WebAuthn.addVirtualAuthenticator', {
await cdpSession.send("WebAuthn.enable", { enableUI: false });
const result = await cdpSession.send("WebAuthn.addVirtualAuthenticator", {
options: {
protocol: 'ctap2',
transport: 'internal',
protocol: "ctap2",
transport: "internal",
hasResidentKey: true,
hasUserVerification: true,
isUserVerified: true,
@@ -23,65 +23,61 @@ async function client(page: Page): Promise<session> {
}
export async function passkeyRegister(page: Page): Promise<string> {
const session = await client(page)
const session = await client(page);
await passkeyNotExisting(session.client, session.authenticatorId);
await simulateSuccessfulPasskeyRegister(
session.client,
session.authenticatorId,
() =>
page.getByTestId("submit-button").click()
await simulateSuccessfulPasskeyRegister(session.client, session.authenticatorId, () =>
page.getByTestId("submit-button").click(),
);
await passkeyRegistered(session.client, session.authenticatorId);
return session.authenticatorId
return session.authenticatorId;
}
export async function passkey(page: Page, authenticatorId: string) {
const cdpSession = await page.context().newCDPSession(page);
await cdpSession.send('WebAuthn.enable', {enableUI: false});
await cdpSession.send("WebAuthn.enable", { enableUI: false });
const signCount = await passkeyExisting(cdpSession, authenticatorId);
await simulateSuccessfulPasskeyInput(
cdpSession,
authenticatorId,
() =>
page.getByTestId("submit-button").click()
);
await simulateSuccessfulPasskeyInput(cdpSession, authenticatorId, () => page.getByTestId("submit-button").click());
await passkeyUsed(cdpSession, authenticatorId, signCount);
}
async function passkeyNotExisting(client: CDPSession, authenticatorId: string) {
const result = await client.send('WebAuthn.getCredentials', {authenticatorId});
const result = await client.send("WebAuthn.getCredentials", { authenticatorId });
expect(result.credentials).toHaveLength(0);
}
async function passkeyRegistered(client: CDPSession, authenticatorId: string) {
const result = await client.send('WebAuthn.getCredentials', {authenticatorId});
const result = await client.send("WebAuthn.getCredentials", { authenticatorId });
expect(result.credentials).toHaveLength(1);
await passkeyUsed(client, authenticatorId, 0);
}
async function passkeyExisting(client: CDPSession, authenticatorId: string): Promise<number> {
const result = await client.send('WebAuthn.getCredentials', {authenticatorId});
const result = await client.send("WebAuthn.getCredentials", { authenticatorId });
expect(result.credentials).toHaveLength(1);
return result.credentials[0].signCount
return result.credentials[0].signCount;
}
async function passkeyUsed(client: CDPSession, authenticatorId: string, signCount: number) {
const result = await client.send('WebAuthn.getCredentials', {authenticatorId});
const result = await client.send("WebAuthn.getCredentials", { authenticatorId });
expect(result.credentials).toHaveLength(1);
expect(result.credentials[0].signCount).toBeGreaterThan(signCount);
}
async function simulateSuccessfulPasskeyRegister(client: CDPSession, authenticatorId: string, operationTrigger: () => Promise<void>) {
async function simulateSuccessfulPasskeyRegister(
client: CDPSession,
authenticatorId: string,
operationTrigger: () => Promise<void>,
) {
// initialize event listeners to wait for a successful passkey input event
const operationCompleted = new Promise<void>(resolve => {
client.on('WebAuthn.credentialAdded', () => {
console.log('Credential Added!');
resolve()
const operationCompleted = new Promise<void>((resolve) => {
client.on("WebAuthn.credentialAdded", () => {
console.log("Credential Added!");
resolve();
});
});
@@ -92,12 +88,16 @@ async function simulateSuccessfulPasskeyRegister(client: CDPSession, authenticat
await operationCompleted;
}
async function simulateSuccessfulPasskeyInput(client: CDPSession, authenticatorId: string, operationTrigger: () => Promise<void>) {
async function simulateSuccessfulPasskeyInput(
client: CDPSession,
authenticatorId: string,
operationTrigger: () => Promise<void>,
) {
// initialize event listeners to wait for a successful passkey input event
const operationCompleted = new Promise<void>(resolve => {
client.on('WebAuthn.credentialAsserted', () => {
console.log('Credential Asserted!');
resolve()
const operationCompleted = new Promise<void>((resolve) => {
client.on("WebAuthn.credentialAsserted", () => {
console.log("Credential Asserted!");
resolve();
});
});

View File

@@ -1,16 +1,16 @@
import { expect, Page } from "@playwright/test";
const passwordField = 'password-text-input'
const passwordConfirmField = 'password-confirm-text-input'
const lengthCheck = "length-check"
const symbolCheck = "symbol-check"
const numberCheck = "number-check"
const uppercaseCheck = "uppercase-check"
const lowercaseCheck = "lowercase-check"
const equalCheck = "equal-check"
const passwordField = "password-text-input";
const passwordConfirmField = "password-confirm-text-input";
const lengthCheck = "length-check";
const symbolCheck = "symbol-check";
const numberCheck = "number-check";
const uppercaseCheck = "uppercase-check";
const lowercaseCheck = "lowercase-check";
const equalCheck = "equal-check";
const matchText = "Matches"
const noMatchText = "Doesn\'t match"
const matchText = "Matches";
const noMatchText = "Doesn't match";
export async function changePasswordScreen(page: Page, password1: string, password2: string) {
await page.getByTestId(passwordField).pressSequentially(password1);
@@ -23,10 +23,20 @@ export async function passwordScreen(page: Page, password: string) {
export async function passwordScreenExpect(page: Page, password: string) {
await expect(page.getByTestId(passwordField)).toHaveValue(password);
await expect(page.getByTestId('error').locator('div')).toContainText("Could not verify password");
await expect(page.getByTestId("error").locator("div")).toContainText("Could not verify password");
}
export async function changePasswordScreenExpect(page: Page, password1: string, password2: string, length: boolean, symbol: boolean, number: boolean, uppercase: boolean, lowercase: boolean, equals: boolean) {
export async function changePasswordScreenExpect(
page: Page,
password1: string,
password2: string,
length: boolean,
symbol: boolean,
number: boolean,
uppercase: boolean,
lowercase: boolean,
equals: boolean,
) {
await expect(page.getByTestId(passwordField)).toHaveValue(password1);
await expect(page.getByTestId(passwordConfirmField)).toHaveValue(password2);

View File

@@ -1,20 +1,19 @@
import { Page } from "@playwright/test";
import { changePasswordScreen, passwordScreen } from "./password-screen";
const passwordSubmitButton = "submit-button"
const passwordSubmitButton = "submit-button";
export async function startChangePassword(page: Page, loginname: string) {
await page.goto('password/change?' + new URLSearchParams({loginName: loginname}));
await page.goto("password/change?" + new URLSearchParams({ loginName: loginname }));
}
export async function changePassword(page: Page, loginname: string, password: string) {
await startChangePassword(page, loginname);
await changePasswordScreen(page, password, password)
await changePasswordScreen(page, password, password);
await page.getByTestId(passwordSubmitButton).click();
}
export async function password(page: Page, password: string) {
await passwordScreen(page, password)
await page.getByTestId(passwordSubmitButton).click()
await passwordScreen(page, password);
await page.getByTestId(passwordSubmitButton).click();
}

View File

@@ -1,16 +1,16 @@
import { Page } from "@playwright/test";
const passwordField = 'password-text-input'
const passwordConfirmField = 'password-confirm-text-input'
const passwordField = "password-text-input";
const passwordConfirmField = "password-confirm-text-input";
export async function registerUserScreenPassword(page: Page, firstname: string, lastname: string, email: string) {
await registerUserScreen(page, firstname, lastname, email)
await page.getByTestId('Password-radio').click();
await registerUserScreen(page, firstname, lastname, email);
await page.getByTestId("Password-radio").click();
}
export async function registerUserScreenPasskey(page: Page, firstname: string, lastname: string, email: string) {
await registerUserScreen(page, firstname, lastname, email)
await page.getByTestId('Passkeys-radio').click();
await registerUserScreen(page, firstname, lastname, email);
await page.getByTestId("Passkeys-radio").click();
}
export async function registerPasswordScreen(page: Page, password1: string, password2: string) {
@@ -19,9 +19,9 @@ export async function registerPasswordScreen(page: Page, password1: string, pass
}
export async function registerUserScreen(page: Page, firstname: string, lastname: string, email: string) {
await page.getByTestId('firstname-text-input').pressSequentially(firstname);
await page.getByTestId('lastname-text-input').pressSequentially(lastname);
await page.getByTestId('email-text-input').pressSequentially(email);
await page.getByTestId('privacy-policy-checkbox').check();
await page.getByTestId('tos-checkbox').check();
await page.getByTestId("firstname-text-input").pressSequentially(firstname);
await page.getByTestId("lastname-text-input").pressSequentially(lastname);
await page.getByTestId("email-text-input").pressSequentially(email);
await page.getByTestId("privacy-policy-checkbox").check();
await page.getByTestId("tos-checkbox").check();
}

View File

@@ -1,30 +1,30 @@
import { test } from "@playwright/test";
import {registerWithPasskey, registerWithPassword} from './register';
import dotenv from "dotenv";
import path from "path";
import { loginScreenExpect } from "./login";
import {removeUserByUsername} from './zitadel';
import path from 'path';
import dotenv from 'dotenv';
import { registerWithPasskey, registerWithPassword } from "./register";
import { removeUserByUsername } from "./zitadel";
// Read from ".env" file.
dotenv.config({path: path.resolve(__dirname, '.env.local')});
dotenv.config({ path: path.resolve(__dirname, ".env.local") });
test("register with password", async ({ page }) => {
const username = "register-password@example.com"
const password = "Password1!"
const firstname = "firstname"
const lastname = "lastname"
const username = "register-password@example.com";
const password = "Password1!";
const firstname = "firstname";
const lastname = "lastname";
await removeUserByUsername(username)
await registerWithPassword(page, firstname, lastname, username, password, password)
await removeUserByUsername(username);
await registerWithPassword(page, firstname, lastname, username, password, password);
await loginScreenExpect(page, firstname + " " + lastname);
});
test("register with passkey", async ({ page }) => {
const username = "register-passkey@example.com"
const firstname = "firstname"
const lastname = "lastname"
const username = "register-passkey@example.com";
const firstname = "firstname";
const lastname = "lastname";
await removeUserByUsername(username)
await registerWithPasskey(page, firstname, lastname, username)
await removeUserByUsername(username);
await registerWithPasskey(page, firstname, lastname, username);
await loginScreenExpect(page, firstname + " " + lastname);
});

View File

@@ -1,18 +1,25 @@
import { Page } from "@playwright/test";
import {passkeyRegister} from './passkey';
import {registerPasswordScreen, registerUserScreenPasskey, registerUserScreenPassword} from './register-screen';
import { passkeyRegister } from "./passkey";
import { registerPasswordScreen, registerUserScreenPasskey, registerUserScreenPassword } from "./register-screen";
export async function registerWithPassword(page: Page, firstname: string, lastname: string, email: string, password1: string, password2: string) {
await page.goto('/register');
await registerUserScreenPassword(page, firstname, lastname, email)
await page.getByTestId('submit-button').click();
await registerPasswordScreen(page, password1, password2)
await page.getByTestId('submit-button').click();
export async function registerWithPassword(
page: Page,
firstname: string,
lastname: string,
email: string,
password1: string,
password2: string,
) {
await page.goto("/register");
await registerUserScreenPassword(page, firstname, lastname, email);
await page.getByTestId("submit-button").click();
await registerPasswordScreen(page, password1, password2);
await page.getByTestId("submit-button").click();
}
export async function registerWithPasskey(page: Page, firstname: string, lastname: string, email: string): Promise<string> {
await page.goto('/register');
await registerUserScreenPasskey(page, firstname, lastname, email)
await page.getByTestId('submit-button').click();
return await passkeyRegister(page)
await page.goto("/register");
await registerUserScreenPasskey(page, firstname, lastname, email);
await page.getByTestId("submit-button").click();
return await passkeyRegister(page);
}

View File

@@ -1,7 +1,7 @@
import fetch from "node-fetch";
import { Page } from "@playwright/test";
import fetch from "node-fetch";
import { registerWithPasskey } from "./register";
import {getUserByUsername, removeUser} from './zitadel';
import { getUserByUsername, removeUser } from "./zitadel";
export interface userProps {
email: string;
@@ -20,12 +20,12 @@ class User {
}
async ensure(page: Page) {
await this.remove()
await this.remove();
const body = {
username: this.props.email,
organization: {
orgId: this.props.organization
orgId: this.props.organization,
},
profile: {
givenName: this.props.firstName,
@@ -37,36 +37,36 @@ class User {
},
password: {
password: this.props.password!,
}
}
},
};
const response = await fetch(process.env.ZITADEL_API_URL! + "/v2/users/human", {
method: 'POST',
method: "POST",
body: JSON.stringify(body),
headers: {
'Content-Type': 'application/json',
'Authorization': "Bearer " + process.env.ZITADEL_SERVICE_USER_TOKEN!
}
"Content-Type": "application/json",
Authorization: "Bearer " + process.env.ZITADEL_SERVICE_USER_TOKEN!,
},
});
if (response.statusCode >= 400 && response.statusCode != 409) {
const error = 'HTTP Error: ' + response.statusCode + ' - ' + response.statusMessage;
const error = "HTTP Error: " + response.statusCode + " - " + response.statusMessage;
console.error(error);
throw new Error(error);
}
return
return;
}
async remove() {
const resp = await getUserByUsername(this.getUsername())
const resp = await getUserByUsername(this.getUsername());
if (!resp || !resp.result || !resp.result[0]) {
return
return;
}
await removeUser(resp.result[0].userId)
return
await removeUser(resp.result[0].userId);
return;
}
public setUserId(userId: string) {
this.user = userId
this.user = userId;
}
public getUserId() {
@@ -82,20 +82,19 @@ class User {
}
public getFirstname() {
return this.props.firstName
return this.props.firstName;
}
public getLastname() {
return this.props.lastName
return this.props.lastName;
}
public getFullName() {
return this.props.firstName + " " + this.props.lastName
return this.props.firstName + " " + this.props.lastName;
}
}
export class PasswordUser extends User {
}
export class PasswordUser extends User {}
export enum OtpType {
sms = "sms",
@@ -107,13 +106,13 @@ export interface otpUserProps {
firstName: string;
lastName: string;
organization: string;
password: string,
type: OtpType,
password: string;
type: OtpType;
}
export class PasswordUserWithOTP extends User {
private type: OtpType
private code: string
private type: OtpType;
private code: string;
constructor(props: otpUserProps) {
super({
@@ -122,41 +121,41 @@ export class PasswordUserWithOTP extends User {
lastName: props.lastName,
organization: props.organization,
password: props.password,
})
this.type = props.type
});
this.type = props.type;
}
async ensure(page: Page) {
await super.ensure(page)
await super.ensure(page);
let url = "otp_"
let url = "otp_";
switch (this.type) {
case OtpType.sms:
url = url + "sms"
url = url + "sms";
case OtpType.email:
url = url + "email"
url = url + "email";
}
const response = await fetch(process.env.ZITADEL_API_URL! + "/v2/users/" + this.getUserId() + "/" + url, {
method: 'POST',
method: "POST",
headers: {
'Content-Type': 'application/json',
'Authorization': "Bearer " + process.env.ZITADEL_SERVICE_USER_TOKEN!
}
"Content-Type": "application/json",
Authorization: "Bearer " + process.env.ZITADEL_SERVICE_USER_TOKEN!,
},
});
if (response.statusCode >= 400 && response.statusCode != 409) {
const error = 'HTTP Error: ' + response.statusCode + ' - ' + response.statusMessage;
const error = "HTTP Error: " + response.statusCode + " - " + response.statusMessage;
console.error(error);
throw new Error(error);
}
// TODO: get code from SMS or Email provider
this.code = ""
return
this.code = "";
return;
}
public getCode() {
return this.code
return this.code;
}
}
@@ -168,7 +167,7 @@ export interface passkeyUserProps {
}
export class PasskeyUser extends User {
private authenticatorId: string
private authenticatorId: string;
constructor(props: passkeyUserProps) {
super({
@@ -176,21 +175,21 @@ export class PasskeyUser extends User {
firstName: props.firstName,
lastName: props.lastName,
organization: props.organization,
password: ""
})
password: "",
});
}
public async ensure(page: Page) {
await this.remove()
const authId = await registerWithPasskey(page, this.getFirstname(), this.getLastname(), this.getUsername())
this.authenticatorId = authId
await this.remove();
const authId = await registerWithPasskey(page, this.getFirstname(), this.getLastname(), this.getUsername());
this.authenticatorId = authId;
}
public async remove() {
await super.remove()
await super.remove();
}
public getAuthenticatorId(): string {
return this.authenticatorId
return this.authenticatorId;
}
}

View File

@@ -1,11 +1,11 @@
import { test as base } from "@playwright/test";
import path from 'path';
import dotenv from 'dotenv';
import {PasskeyUser} from "./user";
import dotenv from "dotenv";
import path from "path";
import { loginScreenExpect, loginWithPasskey } from "./login";
import { PasskeyUser } from "./user";
// Read from ".env" file.
dotenv.config({path: path.resolve(__dirname, '.env.local')});
dotenv.config({ path: path.resolve(__dirname, ".env.local") });
const test = base.extend<{ user: PasskeyUser }>({
user: async ({ page }, use) => {
@@ -21,6 +21,6 @@ const test = base.extend<{ user: PasskeyUser }>({
});
test("username and passkey login", async ({ user, page }) => {
await loginWithPasskey(page, user.getAuthenticatorId(), user.getUsername())
await loginWithPasskey(page, user.getAuthenticatorId(), user.getUsername());
await loginScreenExpect(page, user.getFullName());
});

View File

@@ -1,13 +1,13 @@
import { test as base } from "@playwright/test";
import {PasswordUser} from './user';
import path from 'path';
import dotenv from 'dotenv';
import dotenv from "dotenv";
import path from "path";
import { loginScreenExpect, loginWithPassword } from "./login";
import { changePassword, startChangePassword } from "./password";
import { changePasswordScreen, changePasswordScreenExpect } from "./password-screen";
import { PasswordUser } from "./user";
// Read from ".env" file.
dotenv.config({path: path.resolve(__dirname, '.env.local')});
dotenv.config({ path: path.resolve(__dirname, ".env.local") });
const test = base.extend<{ user: PasswordUser }>({
user: async ({ page }, use) => {
@@ -24,18 +24,18 @@ const test = base.extend<{ user: PasswordUser }>({
});
test("username and password changed login", async ({ user, page }) => {
const changedPw = "ChangedPw1!"
await loginWithPassword(page, user.getUsername(), user.getPassword())
await changePassword(page, user.getUsername(), changedPw)
await loginWithPassword(page, user.getUsername(), changedPw)
const changedPw = "ChangedPw1!";
await loginWithPassword(page, user.getUsername(), user.getPassword());
await changePassword(page, user.getUsername(), changedPw);
await loginWithPassword(page, user.getUsername(), changedPw);
await loginScreenExpect(page, user.getFullName());
});
test("password not with desired complexity", async ({ user, page }) => {
const changedPw1 = "change"
const changedPw2 = "chang"
await loginWithPassword(page, user.getUsername(), user.getPassword())
const changedPw1 = "change";
const changedPw2 = "chang";
await loginWithPassword(page, user.getUsername(), user.getPassword());
await startChangePassword(page, user.getUsername());
await changePasswordScreen(page, changedPw1, changedPw2)
await changePasswordScreenExpect(page, changedPw1, changedPw2, false, false, false, false, true, false)
await changePasswordScreen(page, changedPw1, changedPw2);
await changePasswordScreenExpect(page, changedPw1, changedPw2, false, false, false, false, true, false);
});

View File

@@ -1,12 +1,11 @@
import { test as base } from "@playwright/test";
import {OtpType, PasswordUserWithOTP} from './user';
import path from 'path';
import dotenv from 'dotenv';
import dotenv from "dotenv";
import path from "path";
import { loginScreenExpect, loginWithPassword } from "./login";
import {startSink} from "./otp";
import { OtpType, PasswordUserWithOTP } from "./user";
// Read from ".env" file.
dotenv.config({path: path.resolve(__dirname, '.env.local')});
dotenv.config({ path: path.resolve(__dirname, ".env.local") });
const test = base.extend<{ user: PasswordUserWithOTP }>({
user: async ({ page }, use) => {
@@ -26,11 +25,8 @@ const test = base.extend<{ user: PasswordUserWithOTP }>({
test("username, password and otp login", async ({ user, page }) => {
//const server = startSink()
await loginWithPassword(page, user.getUsername(), user.getPassword())
await loginWithPassword(page, user.getUsername(), user.getPassword());
await loginScreenExpect(page, user.getFullName());
//server.close()
});

View File

@@ -1,50 +1,52 @@
import fetch from "node-fetch";
export async function removeUserByUsername(username: string) {
const resp = await getUserByUsername(username)
const resp = await getUserByUsername(username);
if (!resp || !resp.result || !resp.result[0]) {
return
return;
}
await removeUser(resp.result[0].userId)
await removeUser(resp.result[0].userId);
}
export async function removeUser(id: string) {
const response = await fetch(process.env.ZITADEL_API_URL! + "/v2/users/" + id, {
method: 'DELETE',
method: "DELETE",
headers: {
'Authorization': "Bearer " + process.env.ZITADEL_SERVICE_USER_TOKEN!
}
Authorization: "Bearer " + process.env.ZITADEL_SERVICE_USER_TOKEN!,
},
});
if (response.statusCode >= 400 && response.statusCode != 404) {
const error = 'HTTP Error: ' + response.statusCode + ' - ' + response.statusMessage;
const error = "HTTP Error: " + response.statusCode + " - " + response.statusMessage;
console.error(error);
throw new Error(error);
}
return
return;
}
export async function getUserByUsername(username: string) {
const listUsersBody = {
queries: [{
queries: [
{
userNameQuery: {
userName: username,
}
}]
}
const jsonBody = JSON.stringify(listUsersBody)
},
},
],
};
const jsonBody = JSON.stringify(listUsersBody);
const registerResponse = await fetch(process.env.ZITADEL_API_URL! + "/v2/users", {
method: 'POST',
method: "POST",
body: jsonBody,
headers: {
'Content-Type': 'application/json',
'Authorization': "Bearer " + process.env.ZITADEL_SERVICE_USER_TOKEN!
}
"Content-Type": "application/json",
Authorization: "Bearer " + process.env.ZITADEL_SERVICE_USER_TOKEN!,
},
});
if (registerResponse.statusCode >= 400) {
const error = 'HTTP Error: ' + registerResponse.statusCode + ' - ' + registerResponse.statusMessage;
const error = "HTTP Error: " + registerResponse.statusCode + " - " + registerResponse.statusMessage;
console.error(error);
throw new Error(error);
}
const respJson = await registerResponse.json()
return respJson
const respJson = await registerResponse.json();
return respJson;
}