mirror of
https://github.com/casdoor/casdoor.git
synced 2025-07-15 23:23:50 +08:00
Add getOAuthGetParameters().
This commit is contained in:
@ -29,15 +29,19 @@ export function register(values) {
|
|||||||
}).then(res => res.json());
|
}).then(res => res.json());
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getApplicationLogin(clientId, responseType, redirectUri, scope, state) {
|
function oAuthParamsToQuery(oAuthParams) {
|
||||||
return fetch(`${authConfig.serverUrl}/api/get-app-login?clientId=${clientId}&responseType=${responseType}&redirectUri=${redirectUri}&scope=${scope}&state=${state}`, {
|
return `?clientId=${oAuthParams.clientId}&responseType=${oAuthParams.responseType}&redirectUri=${oAuthParams.redirectUri}&scope=${oAuthParams.scope}&state=${oAuthParams.state}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getApplicationLogin(oAuthParams) {
|
||||||
|
return fetch(`${authConfig.serverUrl}/api/get-app-login${oAuthParamsToQuery(oAuthParams)}`, {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
credentials: 'include',
|
credentials: 'include',
|
||||||
}).then(res => res.json());
|
}).then(res => res.json());
|
||||||
}
|
}
|
||||||
|
|
||||||
export function login(values) {
|
export function login(values, oAuthParams) {
|
||||||
return fetch(`${authConfig.serverUrl}/api/login`, {
|
return fetch(`${authConfig.serverUrl}/api/login${oAuthParamsToQuery(oAuthParams)}`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
credentials: "include",
|
credentials: "include",
|
||||||
body: JSON.stringify(values),
|
body: JSON.stringify(values),
|
||||||
|
@ -46,7 +46,8 @@ class AuthCallback extends React.Component {
|
|||||||
redirectUri: redirectUri,
|
redirectUri: redirectUri,
|
||||||
method: this.state.method,
|
method: this.state.method,
|
||||||
};
|
};
|
||||||
AuthBackend.login(body)
|
const oAuthParams = Util.getOAuthGetParameters();
|
||||||
|
AuthBackend.login(body, oAuthParams)
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
if (res.status === "ok") {
|
if (res.status === "ok") {
|
||||||
window.location.href = '/';
|
window.location.href = '/';
|
||||||
|
@ -42,13 +42,8 @@ class Face extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getApplicationLogin() {
|
getApplicationLogin() {
|
||||||
const queries = new URLSearchParams(window.location.search);
|
const oAuthParams = Util.getOAuthGetParameters();
|
||||||
const clientId = queries.get("client_id");
|
AuthBackend.getApplicationLogin(oAuthParams)
|
||||||
const responseType = queries.get("response_type");
|
|
||||||
const redirectUri = queries.get("redirect_uri");
|
|
||||||
const scope = queries.get("scope");
|
|
||||||
const state = queries.get("state");
|
|
||||||
AuthBackend.getApplicationLogin(clientId, responseType, redirectUri, scope, state)
|
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
if (res.status === "ok") {
|
if (res.status === "ok") {
|
||||||
this.setState({
|
this.setState({
|
||||||
@ -86,8 +81,9 @@ class Face extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onFinish(values) {
|
onFinish(values) {
|
||||||
values.type = this.state.type;
|
values["type"] = this.state.type;
|
||||||
AuthBackend.login(values)
|
const oAuthParams = Util.getOAuthGetParameters();
|
||||||
|
AuthBackend.login(values, oAuthParams)
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
if (res.status === 'ok') {
|
if (res.status === 'ok') {
|
||||||
if (this.state.type === "login") {
|
if (this.state.type === "login") {
|
||||||
|
@ -42,3 +42,23 @@ export function trim(str, ch) {
|
|||||||
|
|
||||||
return (start > 0 || end < str.length) ? str.substring(start, end) : str;
|
return (start > 0 || end < str.length) ? str.substring(start, end) : str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getOAuthGetParameters() {
|
||||||
|
const queries = new URLSearchParams(window.location.search);
|
||||||
|
const clientId = queries.get("client_id");
|
||||||
|
const responseType = queries.get("response_type");
|
||||||
|
const redirectUri = queries.get("redirect_uri");
|
||||||
|
const scope = queries.get("scope");
|
||||||
|
const state = queries.get("state");
|
||||||
|
if (clientId === undefined) {
|
||||||
|
return null;
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
clientId: clientId,
|
||||||
|
responseType: responseType,
|
||||||
|
redirectUri: redirectUri,
|
||||||
|
scope: scope,
|
||||||
|
state: state,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user