Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(api-client): Domain registration #6927

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/api-client/src/APIClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ import {
} from './team/';
import {ScimAPI} from './team/scim/ScimAPI';
import {TeamSearchAPI} from './team/search';
import {SSOAPI} from './team/sso';
import {UserAPI} from './user/';

const {version}: {version: string} = require('../package.json');
Expand Down Expand Up @@ -117,6 +118,7 @@ type Apis = {
scim: ScimAPI;
search: TeamSearchAPI;
service: ServiceAPI;
sso: SSOAPI;
team: TeamAPI;
};
user: UserAPI;
Expand Down Expand Up @@ -227,6 +229,7 @@ export class APIClient extends EventEmitter {
scim: new ScimAPI(this.transport.http),
search: new TeamSearchAPI(this.transport.http),
service: new ServiceAPI(this.transport.http),
sso: new SSOAPI(this.transport.http),
team: new TeamAPI(this.transport.http),
},
user: new UserAPI(this.transport.http, backendFeatures),
Expand Down
52 changes: 52 additions & 0 deletions packages/api-client/src/account/AccountAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@
import {AxiosRequestConfig} from 'axios';

import {CustomBackendNotFoundError} from './AccountError';
import {BackendConfig} from './BackendConfig';
import {BackendConfigData} from './BackendConfigData';
import {CallConfigData} from './CallConfigData';
import {DomainData} from './DomainData';
import {DomainRedirect, DomainRedirectType} from './DomainRedirect';
import {SSOSettings} from './SSOSettings';

import {HttpClient, BackendErrorLabel, BackendError} from '../http';
Expand All @@ -44,6 +46,7 @@ export class AccountAPI {
PROVIDER: '/provider',
SETTINGS: 'settings',
SSO: '/sso',
GET_DOMAIN_REGISTRATION: '/get-domain-registration',
};

/**
Expand Down Expand Up @@ -222,4 +225,53 @@ export class AccountAPI {
const response = await this.client.sendJSON<BackendConfigData>(config);
return response.data;
}

public async getDomainRegistration(email: string): Promise<DomainRedirect> {
return new Promise(resolve => {
if (email.includes('no-reg')) {
resolve({
type: DomainRedirectType.CLOUD_NO_REGISTRATION,
});
} else if (email.includes('locked')) {
resolve({
type: DomainRedirectType.CLOUD,
});
} else if (email.includes('backend')) {
resolve({
type: DomainRedirectType.CUSTOM_BACKEND,
payload: {
backend: {
url: 'anta.wire.link',
},
},
});
} else if (email.includes('sso')) {
resolve({
type: DomainRedirectType.SSO,
payload: {
sso: {
code: 'test',
},
},
});
} else {
resolve({type: DomainRedirectType.CLOUD});
}
});
}

public async getBackendConfig(url: string): Promise<BackendConfig> {
return new Promise(resolve => {
resolve({
backendName: 'Anta',
webAppURL: 'https://webapp.anta.wire.link/',
backendURL: `https://nginz-https.${url}`,
backendWSURL: `wss://nginz-ssl.${url}`,
blacklistURL: `wss://nginz-ssl.${url}`,
teamsURL: `https://teams.${url}`,
accountURL: `https://account.${url}`,
websiteURL: `https://webapp.${url}`,
});
});
}
}
29 changes: 29 additions & 0 deletions packages/api-client/src/account/BackendConfig.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Wire
* Copyright (C) 2024 Wire Swiss GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://www.gnu.org/licenses/.
*
*/

export interface BackendConfig {
backendName: string;
backendURL: string;
backendWSURL: string;
blacklistURL: string;
teamsURL: string;
accountURL: string;
websiteURL: string;
webAppURL: string;
}
41 changes: 41 additions & 0 deletions packages/api-client/src/account/DomainRedirect.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Wire
* Copyright (C) 2024 Wire Swiss GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://www.gnu.org/licenses/.
*
*/

export enum DomainRedirectType {
CLOUD,
CLOUD_NO_REGISTRATION,
SSO,
CUSTOM_BACKEND,
}

export type DomainRedirect =
| {
type: DomainRedirectType.CLOUD;
}
| {
type: DomainRedirectType.CLOUD_NO_REGISTRATION;
}
| {
type: DomainRedirectType.SSO;
payload: {sso: {code: string}};
}
| {
type: DomainRedirectType.CUSTOM_BACKEND;
payload: {backend: {url: string}};
};
131 changes: 131 additions & 0 deletions packages/api-client/src/team/sso/SSOAPI.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
/*
* Wire
* Copyright (C) 2021 Wire Swiss GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://www.gnu.org/licenses/.
*
*/

import {AxiosRequestConfig} from 'axios';

import {
DomainVerificationChallenge,
RegisteredDomain,
TeamInviteConfig,
VerifyChallenge,
VerifyChallengeRequest,
VerifyDomainRedirectConfig,
} from './SSOAPI.types';

import {HttpClient} from '../../http';
import {TeamAPI} from '../team';

export class SSOAPI {
constructor(private readonly client: HttpClient) {}

public static readonly URL = {
AUTHORIZE_TEAM: 'authorize-team',
BACKEND: 'backend',
CHALLENGES: 'challenges',
DOMAIN_VERIFICATION: '/domain-verification',
REGISTERED_DOMAINS: 'registered-domains',
TEAM: 'team',
};

public async authorizeTeam(domain: string, domainOwnershipToken: string): Promise<unknown> {
const config: AxiosRequestConfig = {
data: {
domain_ownership_token: domainOwnershipToken,
},
method: 'post',
url: `${SSOAPI.URL.DOMAIN_VERIFICATION}/${domain}/${SSOAPI.URL.AUTHORIZE_TEAM}`,
};

return await this.client.sendJSON(config);
}

public async updateDomainRedirect({domain, backendUrl, domainRedirect}: VerifyDomainRedirectConfig) {
const config: AxiosRequestConfig = {
data: {
backend_url: backendUrl,
domainRedirect: domainRedirect,
},
method: 'post',
url: `${SSOAPI.URL.DOMAIN_VERIFICATION}/${domain}/${SSOAPI.URL.BACKEND}`,
};

const response = await this.client.sendJSON(config);
return response.data;
}

public async domainVerificationChallenge(domain: string): Promise<DomainVerificationChallenge> {
const config: AxiosRequestConfig = {
method: 'post',
url: `${SSOAPI.URL.DOMAIN_VERIFICATION}/${domain}/${SSOAPI.URL.CHALLENGES}`,
};

const response = await this.client.sendJSON<DomainVerificationChallenge>(config);
return response.data;
}

public async verifyChallenge({
domain,
challengeId,
challengeToken,
}: VerifyChallengeRequest): Promise<VerifyChallenge> {
const config: AxiosRequestConfig = {
data: {
challenge_token: challengeToken,
},
method: 'post',
url: `${SSOAPI.URL.DOMAIN_VERIFICATION}/${domain}/${SSOAPI.URL.CHALLENGES}/${challengeId}`,
};

const response = await this.client.sendJSON<VerifyChallenge>(config);
return response.data;
}

public async updateTeamInvite({domain, sso, team, teamInvite}: TeamInviteConfig): Promise<void> {
const config: AxiosRequestConfig = {
data: {
sso,
team,
team_invite: teamInvite,
},
method: 'post',
url: `${SSOAPI.URL.DOMAIN_VERIFICATION}/${domain}/${SSOAPI.URL.TEAM}`,
};

await this.client.sendJSON(config);
}

public async getAllRegisteredDomains(teamId: string): Promise<RegisteredDomain[]> {
const config: AxiosRequestConfig = {
method: 'get',
url: `${TeamAPI.URL.TEAMS}/${teamId}/${SSOAPI.URL.REGISTERED_DOMAINS}`,
};

const response = await this.client.sendJSON<RegisteredDomain[]>(config);
return response.data;
}

public async deleteRegisteredDomain(teamId: string, domain: string): Promise<void> {
const config: AxiosRequestConfig = {
method: 'delete',
url: `${TeamAPI.URL.TEAMS}/${teamId}/${SSOAPI.URL.REGISTERED_DOMAINS}/${domain}`,
};

await this.client.sendJSON(config);
}
}
62 changes: 62 additions & 0 deletions packages/api-client/src/team/sso/SSOAPI.types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Wire
* Copyright (C) 2021 Wire Swiss GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://www.gnu.org/licenses/.
*
*/

export interface VerifyDomainRedirectConfig {
domain: string;
backendUrl: string;
domainRedirect: 'remove' | 'backend' | 'no-registration';
}

export interface DomainVerificationChallenge {
dns_verification_token: string;
id: string;
token: string;
}

export interface VerifyChallengeRequest {
domain: string;
challengeId: string;
challengeToken: string;
}

export interface VerifyChallenge {
domain_ownership_token: string;
}

export type TeamInvite = 'allowed' | 'not-allowed' | 'team';

export interface TeamInviteConfig {
domain: string;
sso: string;
team: string;
teamInvite: TeamInvite;
}

export type DomainRedirect = 'none' | 'locked' | 'sso' | 'backend' | 'no-registration' | 'pre-authorized';

export interface RegisteredDomain {
authorized_team: string;
backend_url: string;
dns_verification_token: string;
domain: string;
domain_redirect: DomainRedirect;
sso_code: string;
team: string;
team_invite: TeamInvite;
}
21 changes: 21 additions & 0 deletions packages/api-client/src/team/sso/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Wire
* Copyright (C) 2025 Wire Swiss GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://www.gnu.org/licenses/.
*
*/

export * from './SSOAPI';
export * from './SSOAPI.types';