2022-02-13 23:39:27 +08:00
|
|
|
// Copyright 2021 The Casdoor Authors. All Rights Reserved.
|
2021-02-13 12:15:19 +08:00
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
2021-02-14 16:59:08 +08:00
|
|
|
import {authConfig} from "./Auth";
|
2022-10-23 15:16:24 +08:00
|
|
|
import * as Setting from "../Setting";
|
2021-02-14 15:51:56 +08:00
|
|
|
|
2023-05-17 01:13:13 +08:00
|
|
|
export function getAccount(query = "") {
|
2021-05-16 18:18:55 +08:00
|
|
|
return fetch(`${authConfig.serverUrl}/api/get-account${query}`, {
|
2022-07-10 15:45:55 +08:00
|
|
|
method: "GET",
|
2022-08-06 23:54:56 +08:00
|
|
|
credentials: "include",
|
2022-10-23 15:16:24 +08:00
|
|
|
headers: {
|
|
|
|
"Accept-Language": Setting.getAcceptLanguage(),
|
|
|
|
},
|
2021-02-13 12:15:19 +08:00
|
|
|
}).then(res => res.json());
|
|
|
|
}
|
|
|
|
|
2021-04-27 22:47:44 +08:00
|
|
|
export function signup(values) {
|
|
|
|
return fetch(`${authConfig.serverUrl}/api/signup`, {
|
2022-07-10 15:45:55 +08:00
|
|
|
method: "POST",
|
2021-02-13 12:15:19 +08:00
|
|
|
credentials: "include",
|
|
|
|
body: JSON.stringify(values),
|
2022-10-23 15:16:24 +08:00
|
|
|
headers: {
|
|
|
|
"Accept-Language": Setting.getAcceptLanguage(),
|
|
|
|
},
|
2021-02-13 12:15:19 +08:00
|
|
|
}).then(res => res.json());
|
|
|
|
}
|
|
|
|
|
2023-03-01 15:57:42 +08:00
|
|
|
export function getEmailAndPhone(organization, username) {
|
2025-05-23 11:29:00 +02:00
|
|
|
return fetch(`${authConfig.serverUrl}/api/get-email-and-phone?organization=${organization}&username=${encodeURIComponent(username)}`, {
|
2023-03-01 15:57:42 +08:00
|
|
|
method: "GET",
|
2021-06-02 13:39:01 +08:00
|
|
|
credentials: "include",
|
2022-10-23 15:16:24 +08:00
|
|
|
headers: {
|
|
|
|
"Accept-Language": Setting.getAcceptLanguage(),
|
|
|
|
},
|
2021-06-02 13:39:01 +08:00
|
|
|
}).then((res) => res.json());
|
|
|
|
}
|
|
|
|
|
2023-08-19 01:05:55 +08:00
|
|
|
export function casLoginParamsToQuery(casParams) {
|
|
|
|
return `?type=${casParams?.type}&id=${casParams?.id}&redirectUri=${casParams?.service}`;
|
|
|
|
}
|
|
|
|
|
2022-10-01 11:10:55 +08:00
|
|
|
export function oAuthParamsToQuery(oAuthParams) {
|
2021-08-01 11:20:06 +08:00
|
|
|
// login
|
2023-05-05 21:23:59 +08:00
|
|
|
if (oAuthParams === null || oAuthParams === undefined) {
|
2021-08-01 11:20:06 +08:00
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
// code
|
2023-08-19 01:05:55 +08:00
|
|
|
return `?clientId=${oAuthParams.clientId}&responseType=${oAuthParams.responseType}&redirectUri=${encodeURIComponent(oAuthParams.redirectUri)}&type=${oAuthParams.type}&scope=${oAuthParams.scope}&state=${oAuthParams.state}&nonce=${oAuthParams.nonce}&code_challenge_method=${oAuthParams.challengeMethod}&code_challenge=${oAuthParams.codeChallenge}`;
|
2021-03-20 16:51:10 +08:00
|
|
|
}
|
|
|
|
|
2023-08-19 01:05:55 +08:00
|
|
|
export function getApplicationLogin(params) {
|
2025-04-30 23:42:26 +08:00
|
|
|
let queryParams = "";
|
|
|
|
if (params?.type === "cas") {
|
|
|
|
queryParams = casLoginParamsToQuery(params);
|
|
|
|
} else if (params?.type === "device") {
|
|
|
|
queryParams = `?userCode=${params.userCode}&type=device`;
|
|
|
|
} else {
|
|
|
|
queryParams = oAuthParamsToQuery(params);
|
|
|
|
}
|
2023-08-19 01:05:55 +08:00
|
|
|
return fetch(`${authConfig.serverUrl}/api/get-app-login${queryParams}`, {
|
2022-07-10 15:45:55 +08:00
|
|
|
method: "GET",
|
|
|
|
credentials: "include",
|
2022-10-23 15:16:24 +08:00
|
|
|
headers: {
|
|
|
|
"Accept-Language": Setting.getAcceptLanguage(),
|
|
|
|
},
|
2021-03-20 11:34:04 +08:00
|
|
|
}).then(res => res.json());
|
|
|
|
}
|
|
|
|
|
2021-03-20 16:51:10 +08:00
|
|
|
export function login(values, oAuthParams) {
|
|
|
|
return fetch(`${authConfig.serverUrl}/api/login${oAuthParamsToQuery(oAuthParams)}`, {
|
2022-07-10 15:45:55 +08:00
|
|
|
method: "POST",
|
2021-02-13 12:15:19 +08:00
|
|
|
credentials: "include",
|
|
|
|
body: JSON.stringify(values),
|
2022-10-23 15:16:24 +08:00
|
|
|
headers: {
|
|
|
|
"Accept-Language": Setting.getAcceptLanguage(),
|
|
|
|
},
|
2021-02-13 12:15:19 +08:00
|
|
|
}).then(res => res.json());
|
|
|
|
}
|
|
|
|
|
2022-04-04 00:09:04 +08:00
|
|
|
export function loginCas(values, params) {
|
|
|
|
return fetch(`${authConfig.serverUrl}/api/login?service=${params.service}`, {
|
2022-07-10 15:45:55 +08:00
|
|
|
method: "POST",
|
2022-04-04 00:09:04 +08:00
|
|
|
credentials: "include",
|
|
|
|
body: JSON.stringify(values),
|
2022-10-23 15:16:24 +08:00
|
|
|
headers: {
|
|
|
|
"Accept-Language": Setting.getAcceptLanguage(),
|
|
|
|
},
|
2022-04-04 00:09:04 +08:00
|
|
|
}).then(res => res.json());
|
|
|
|
}
|
|
|
|
|
2021-02-13 12:15:19 +08:00
|
|
|
export function logout() {
|
2021-02-14 16:59:08 +08:00
|
|
|
return fetch(`${authConfig.serverUrl}/api/logout`, {
|
2022-07-10 15:45:55 +08:00
|
|
|
method: "POST",
|
2021-02-13 12:15:19 +08:00
|
|
|
credentials: "include",
|
2022-10-23 15:16:24 +08:00
|
|
|
headers: {
|
|
|
|
"Accept-Language": Setting.getAcceptLanguage(),
|
|
|
|
},
|
2021-02-13 12:15:19 +08:00
|
|
|
}).then(res => res.json());
|
|
|
|
}
|
2021-02-14 00:22:24 +08:00
|
|
|
|
2021-04-18 23:14:46 +08:00
|
|
|
export function unlink(values) {
|
|
|
|
return fetch(`${authConfig.serverUrl}/api/unlink`, {
|
2022-07-10 15:45:55 +08:00
|
|
|
method: "POST",
|
2021-04-18 23:14:46 +08:00
|
|
|
credentials: "include",
|
|
|
|
body: JSON.stringify(values),
|
2022-10-23 15:16:24 +08:00
|
|
|
headers: {
|
|
|
|
"Accept-Language": Setting.getAcceptLanguage(),
|
|
|
|
},
|
2021-02-14 16:59:08 +08:00
|
|
|
}).then(res => res.json());
|
|
|
|
}
|
2021-12-06 21:46:50 +08:00
|
|
|
|
2021-12-15 21:38:00 +08:00
|
|
|
export function getSamlLogin(providerId, relayState) {
|
|
|
|
return fetch(`${authConfig.serverUrl}/api/get-saml-login?id=${providerId}&relayState=${relayState}`, {
|
2022-07-10 15:45:55 +08:00
|
|
|
method: "GET",
|
|
|
|
credentials: "include",
|
2022-10-23 15:16:24 +08:00
|
|
|
headers: {
|
|
|
|
"Accept-Language": Setting.getAcceptLanguage(),
|
|
|
|
},
|
2021-12-06 21:46:50 +08:00
|
|
|
}).then(res => res.json());
|
|
|
|
}
|
|
|
|
|
2021-12-10 00:23:04 +08:00
|
|
|
export function loginWithSaml(values, param) {
|
|
|
|
return fetch(`${authConfig.serverUrl}/api/login${param}`, {
|
2022-07-10 15:45:55 +08:00
|
|
|
method: "POST",
|
2021-12-06 21:46:50 +08:00
|
|
|
credentials: "include",
|
|
|
|
body: JSON.stringify(values),
|
2022-10-23 15:16:24 +08:00
|
|
|
headers: {
|
|
|
|
"Accept-Language": Setting.getAcceptLanguage(),
|
|
|
|
},
|
2021-12-06 21:46:50 +08:00
|
|
|
}).then(res => res.json());
|
2022-07-10 15:45:55 +08:00
|
|
|
}
|
2022-11-13 15:05:15 +08:00
|
|
|
|
2024-02-05 21:38:12 +08:00
|
|
|
export function getWechatMessageEvent(ticket) {
|
|
|
|
return fetch(`${Setting.ServerUrl}/api/get-webhook-event?ticket=${ticket}`, {
|
|
|
|
method: "GET",
|
|
|
|
credentials: "include",
|
|
|
|
headers: {
|
|
|
|
"Accept-Language": Setting.getAcceptLanguage(),
|
|
|
|
},
|
|
|
|
}).then(res => res.json());
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getWechatQRCode(providerId) {
|
|
|
|
return fetch(`${Setting.ServerUrl}/api/get-qrcode?id=${providerId}`, {
|
2022-11-13 15:05:15 +08:00
|
|
|
method: "GET",
|
|
|
|
credentials: "include",
|
|
|
|
headers: {
|
|
|
|
"Accept-Language": Setting.getAcceptLanguage(),
|
|
|
|
},
|
|
|
|
}).then(res => res.json());
|
|
|
|
}
|
2023-04-22 16:16:25 +08:00
|
|
|
|
|
|
|
export function getCaptchaStatus(values) {
|
2024-01-13 18:03:40 +08:00
|
|
|
return fetch(`${Setting.ServerUrl}/api/get-captcha-status?organization=${values["organization"]}&userId=${values["username"]}`, {
|
2023-04-22 16:16:25 +08:00
|
|
|
method: "GET",
|
|
|
|
credentials: "include",
|
|
|
|
headers: {
|
|
|
|
"Accept-Language": Setting.getAcceptLanguage(),
|
|
|
|
},
|
|
|
|
}).then(res => res.json());
|
|
|
|
}
|