-
Notifications
You must be signed in to change notification settings - Fork 3.5k
/
AccountAPI.js
50 lines (40 loc) · 1.23 KB
/
AccountAPI.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import api from './API';
import { getEnvVars } from '../../Environment';
const { oAuthConfig } = getEnvVars();
getLoginData = (username, password) => {
const formData = {
grant_type: 'password',
scope: oAuthConfig.scope,
username: username,
password: password,
client_id: oAuthConfig.clientId
};
if (oAuthConfig.clientSecret)
formData['client_secret'] = oAuthConfig.clientSecret;
return Object.entries(formData)
.map(([key, value]) => `${key}=${encodeURIComponent(value)}`)
.join('&');
}
export const login = ({ username, password }) =>
api({
method: 'POST',
url: '/connect/token',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
data: getLoginData(username, password),
baseURL: oAuthConfig.issuer
}).then(({ data }) => data);
export const Logout = () =>
api({
method: 'GET',
url: '/api/account/logout',
}).then(({ data }) => data);
export const getTenant = tenantName =>
api({
method: 'GET',
url: `/api/abp/multi-tenancy/tenants/by-name/${tenantName}`,
}).then(({ data }) => data);
export const getTenantById = tenantId =>
api({
method: 'GET',
url: `/api/abp/multi-tenancy/tenants/by-id/${tenantId}`,
}).then(({ data }) => data);