2025-01-19 19:12:00 +01:00
|
|
|
|
2025-07-10 11:55:11 +02:00
|
|
|
import { fetcher } from '@cloudron/pankow';
|
2025-03-03 11:22:56 +01:00
|
|
|
import { API_ORIGIN } from '../constants.js';
|
2025-01-19 19:12:00 +01:00
|
|
|
|
2025-01-31 21:02:48 +01:00
|
|
|
function create() {
|
|
|
|
|
const accessToken = localStorage.token;
|
|
|
|
|
|
2025-01-19 19:12:00 +01:00
|
|
|
return {
|
|
|
|
|
async getGlobalProfileConfig() {
|
|
|
|
|
let error, result;
|
|
|
|
|
try {
|
2025-03-03 11:22:56 +01:00
|
|
|
result = await fetcher.get(`${API_ORIGIN}/api/v1/user_directory/profile_config`, { access_token: accessToken });
|
2025-01-19 19:12:00 +01:00
|
|
|
} catch (e) {
|
|
|
|
|
error = e;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (error || result.status !== 200) return [error || result];
|
|
|
|
|
return [null, result.body];
|
|
|
|
|
},
|
|
|
|
|
async setGlobalProfileConfig(config) {
|
|
|
|
|
let error, result;
|
|
|
|
|
try {
|
2025-03-03 11:22:56 +01:00
|
|
|
result = await fetcher.post(`${API_ORIGIN}/api/v1/user_directory/profile_config`, config, { access_token: accessToken });
|
2025-01-19 19:12:00 +01:00
|
|
|
} catch (e) {
|
|
|
|
|
error = e;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (error || result.status !== 200) return [error || result];
|
|
|
|
|
return [null];
|
|
|
|
|
},
|
|
|
|
|
async getExternalLdapConfig() {
|
|
|
|
|
let error, result;
|
|
|
|
|
try {
|
2025-03-03 11:22:56 +01:00
|
|
|
result = await fetcher.get(`${API_ORIGIN}/api/v1/external_ldap/config`, { access_token: accessToken });
|
2025-01-19 19:12:00 +01:00
|
|
|
} catch (e) {
|
|
|
|
|
error = e;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (error || result.status !== 200) return [error || result];
|
|
|
|
|
return [null, result.body];
|
|
|
|
|
},
|
|
|
|
|
async setExternalLdapConfig(config) {
|
|
|
|
|
let error, result;
|
|
|
|
|
try {
|
2025-03-03 11:22:56 +01:00
|
|
|
result = await fetcher.post(`${API_ORIGIN}/api/v1/external_ldap/config`, config, { access_token: accessToken });
|
2025-01-19 19:12:00 +01:00
|
|
|
} catch (e) {
|
|
|
|
|
error = e;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (error || result.status !== 200) return [error || result];
|
|
|
|
|
return [null];
|
|
|
|
|
},
|
|
|
|
|
async startExternalLdapSync() {
|
|
|
|
|
let error, result;
|
|
|
|
|
try {
|
2025-03-03 11:22:56 +01:00
|
|
|
result = await fetcher.post(`${API_ORIGIN}/api/v1/external_ldap/sync`, {}, { access_token: accessToken });
|
2025-01-19 19:12:00 +01:00
|
|
|
} catch (e) {
|
|
|
|
|
error = e;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (error || result.status !== 202) return [error || result];
|
|
|
|
|
return [null, result.body.taskId];
|
|
|
|
|
},
|
|
|
|
|
async getExposedLdapConfig() {
|
|
|
|
|
let error, result;
|
|
|
|
|
try {
|
2025-03-03 11:22:56 +01:00
|
|
|
result = await fetcher.get(`${API_ORIGIN}/api/v1/directory_server/config`, { access_token: accessToken });
|
2025-01-19 19:12:00 +01:00
|
|
|
} catch (e) {
|
|
|
|
|
error = e;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (error || result.status !== 200) return [error || result];
|
|
|
|
|
return [null, result.body];
|
|
|
|
|
},
|
|
|
|
|
async setExposedLdapConfig(config) {
|
|
|
|
|
const data = {
|
|
|
|
|
enabled: config.enabled,
|
|
|
|
|
allowlist: config.allowlist,
|
|
|
|
|
secret: config.secret,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
let error, result;
|
|
|
|
|
try {
|
2025-03-03 11:22:56 +01:00
|
|
|
result = await fetcher.post(`${API_ORIGIN}/api/v1/directory_server/config`, data, { access_token: accessToken });
|
2025-01-19 19:12:00 +01:00
|
|
|
} catch (e) {
|
|
|
|
|
error = e;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (error || result.status !== 202) return [error || result];
|
|
|
|
|
return [null];
|
|
|
|
|
},
|
2025-01-19 19:53:29 +01:00
|
|
|
async getOpenIdClients() {
|
|
|
|
|
let error, result;
|
|
|
|
|
try {
|
2025-03-03 11:22:56 +01:00
|
|
|
result = await fetcher.get(`${API_ORIGIN}/api/v1/oidc/clients`, { access_token: accessToken });
|
2025-01-19 19:53:29 +01:00
|
|
|
} catch (e) {
|
|
|
|
|
error = e;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (error || result.status !== 200) return [error || result];
|
|
|
|
|
return [null, result.body.clients];
|
|
|
|
|
},
|
|
|
|
|
async addOpenIdClient(name, loginRedirectUri, tokenSignatureAlgorithm) {
|
|
|
|
|
let error, result;
|
|
|
|
|
try {
|
2025-03-03 11:22:56 +01:00
|
|
|
result = await fetcher.post(`${API_ORIGIN}/api/v1/oidc/clients`, { name, loginRedirectUri, tokenSignatureAlgorithm }, { access_token: accessToken });
|
2025-01-19 19:53:29 +01:00
|
|
|
} catch (e) {
|
|
|
|
|
error = e;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (error || result.status !== 201) return [error || result];
|
2025-09-12 19:00:19 +02:00
|
|
|
return [null, result.body];
|
2025-01-19 19:53:29 +01:00
|
|
|
},
|
|
|
|
|
async updateOpenIdClient(id, name, loginRedirectUri, tokenSignatureAlgorithm) {
|
|
|
|
|
let error, result;
|
|
|
|
|
try {
|
2025-03-03 11:22:56 +01:00
|
|
|
result = await fetcher.post(`${API_ORIGIN}/api/v1/oidc/clients/${id}`, { name, loginRedirectUri, tokenSignatureAlgorithm }, { access_token: accessToken });
|
2025-01-19 19:53:29 +01:00
|
|
|
} catch (e) {
|
|
|
|
|
error = e;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (error || result.status !== 201) return [error || result];
|
|
|
|
|
return [null];
|
|
|
|
|
},
|
|
|
|
|
async removeOpenIdClient(id) {
|
|
|
|
|
let error, result;
|
|
|
|
|
try {
|
2025-03-14 18:48:13 +01:00
|
|
|
result = await fetcher.del(`${API_ORIGIN}/api/v1/oidc/clients/${id}`, null, { access_token: accessToken });
|
2025-01-19 19:53:29 +01:00
|
|
|
} catch (e) {
|
|
|
|
|
error = e;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (error || result.status !== 204) return [error || result];
|
|
|
|
|
return [null];
|
|
|
|
|
},
|
2025-01-19 19:12:00 +01:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default {
|
|
|
|
|
create,
|
|
|
|
|
};
|