mirror of
https://github.com/casdoor/casdoor.git
synced 2025-09-10 08:22:56 +08:00
feat: fix the error effect of form post response type (#4003)
This commit is contained in:
@@ -1816,3 +1816,24 @@ export function renderLoginPanel(application, getInnerComponent, componentThis)
|
|||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function createFormAndSubmit(url, params) {
|
||||||
|
const form = document.createElement("form");
|
||||||
|
form.method = "post";
|
||||||
|
form.action = url;
|
||||||
|
|
||||||
|
for (const k in params) {
|
||||||
|
if (!params[k]) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const input = document.createElement("input");
|
||||||
|
input.type = "hidden";
|
||||||
|
input.name = k;
|
||||||
|
input.value = params[k];
|
||||||
|
form.appendChild(input);
|
||||||
|
}
|
||||||
|
|
||||||
|
document.body.appendChild(form);
|
||||||
|
form.submit();
|
||||||
|
setTimeout(() => {form.remove();}, 500);
|
||||||
|
}
|
||||||
|
@@ -21,7 +21,7 @@ import {authConfig} from "./Auth";
|
|||||||
import * as Setting from "../Setting";
|
import * as Setting from "../Setting";
|
||||||
import i18next from "i18next";
|
import i18next from "i18next";
|
||||||
import RedirectForm from "../common/RedirectForm";
|
import RedirectForm from "../common/RedirectForm";
|
||||||
import {renderLoginPanel} from "../Setting";
|
import {createFormAndSubmit, renderLoginPanel} from "../Setting";
|
||||||
|
|
||||||
class AuthCallback extends React.Component {
|
class AuthCallback extends React.Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
@@ -35,30 +35,6 @@ class AuthCallback extends React.Component {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
submitFormPost(redirectUri, code, state) {
|
|
||||||
const form = document.createElement("form");
|
|
||||||
form.method = "post";
|
|
||||||
form.action = redirectUri;
|
|
||||||
|
|
||||||
const codeInput = document.createElement("input");
|
|
||||||
codeInput.type = "hidden";
|
|
||||||
codeInput.name = "code";
|
|
||||||
codeInput.value = code;
|
|
||||||
form.appendChild(codeInput);
|
|
||||||
|
|
||||||
if (state) {
|
|
||||||
const stateInput = document.createElement("input");
|
|
||||||
stateInput.type = "hidden";
|
|
||||||
stateInput.name = "state";
|
|
||||||
stateInput.value = state;
|
|
||||||
form.appendChild(stateInput);
|
|
||||||
}
|
|
||||||
|
|
||||||
document.body.appendChild(form);
|
|
||||||
form.submit();
|
|
||||||
setTimeout(() => form.remove(), 1000);
|
|
||||||
}
|
|
||||||
|
|
||||||
getInnerParams() {
|
getInnerParams() {
|
||||||
// For example, for Casbin-OA, realRedirectUri = "http://localhost:9000/login"
|
// For example, for Casbin-OA, realRedirectUri = "http://localhost:9000/login"
|
||||||
// realRedirectUrl = "http://localhost:9000"
|
// realRedirectUrl = "http://localhost:9000"
|
||||||
@@ -189,6 +165,7 @@ class AuthCallback extends React.Component {
|
|||||||
.then((res) => {
|
.then((res) => {
|
||||||
if (res.status === "ok") {
|
if (res.status === "ok") {
|
||||||
const responseType = this.getResponseType();
|
const responseType = this.getResponseType();
|
||||||
|
const responseTypes = responseType.split(" ");
|
||||||
const handleLogin = (res) => {
|
const handleLogin = (res) => {
|
||||||
if (responseType === "login") {
|
if (responseType === "login") {
|
||||||
if (res.data3) {
|
if (res.data3) {
|
||||||
@@ -208,20 +185,35 @@ class AuthCallback extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (responseMode === "form_post") {
|
if (responseMode === "form_post") {
|
||||||
this.submitFormPost(oAuthParams?.redirectUri, res.data, oAuthParams?.state);
|
const params = {
|
||||||
|
code: res.data,
|
||||||
|
state: oAuthParams?.state,
|
||||||
|
};
|
||||||
|
createFormAndSubmit(oAuthParams?.redirectUri, params);
|
||||||
} else {
|
} else {
|
||||||
const code = res.data;
|
const code = res.data;
|
||||||
Setting.goToLink(`${oAuthParams.redirectUri}${concatChar}code=${code}&state=${oAuthParams.state}`);
|
Setting.goToLink(`${oAuthParams.redirectUri}${concatChar}code=${code}&state=${oAuthParams.state}`);
|
||||||
}
|
}
|
||||||
// Setting.showMessage("success", `Authorization code: ${res.data}`);
|
// Setting.showMessage("success", `Authorization code: ${res.data}`);
|
||||||
} else if (responseType === "token" || responseType === "id_token") {
|
} else if (responseTypes.includes("token") || responseTypes.includes("id_token")) {
|
||||||
if (res.data3) {
|
if (res.data3) {
|
||||||
sessionStorage.setItem("signinUrl", signinUrl);
|
sessionStorage.setItem("signinUrl", signinUrl);
|
||||||
Setting.goToLinkSoft(this, `/forget/${applicationName}`);
|
Setting.goToLinkSoft(this, `/forget/${applicationName}`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const token = res.data;
|
|
||||||
Setting.goToLink(`${oAuthParams.redirectUri}${concatChar}${responseType}=${token}&state=${oAuthParams.state}&token_type=bearer`);
|
if (responseMode === "form_post") {
|
||||||
|
const params = {
|
||||||
|
token: responseTypes.includes("token") ? res.data : null,
|
||||||
|
id_token: responseTypes.includes("id_token") ? res.data : null,
|
||||||
|
token_type: "bearer",
|
||||||
|
state: oAuthParams?.state,
|
||||||
|
};
|
||||||
|
createFormAndSubmit(oAuthParams?.redirectUri, params);
|
||||||
|
} else {
|
||||||
|
const token = res.data;
|
||||||
|
Setting.goToLink(`${oAuthParams.redirectUri}${concatChar}${responseType}=${token}&state=${oAuthParams.state}&token_type=bearer`);
|
||||||
|
}
|
||||||
} else if (responseType === "link") {
|
} else if (responseType === "link") {
|
||||||
let from = innerParams.get("from");
|
let from = innerParams.get("from");
|
||||||
const oauth = innerParams.get("oauth");
|
const oauth = innerParams.get("oauth");
|
||||||
|
@@ -37,7 +37,7 @@ import RedirectForm from "../common/RedirectForm";
|
|||||||
import {RequiredMfa} from "./mfa/MfaAuthVerifyForm";
|
import {RequiredMfa} from "./mfa/MfaAuthVerifyForm";
|
||||||
import {GoogleOneTapLoginVirtualButton} from "./GoogleLoginButton";
|
import {GoogleOneTapLoginVirtualButton} from "./GoogleLoginButton";
|
||||||
import * as ProviderButton from "./ProviderButton";
|
import * as ProviderButton from "./ProviderButton";
|
||||||
import {goToLink} from "../Setting";
|
import {createFormAndSubmit, goToLink} from "../Setting";
|
||||||
import WeChatLoginPanel from "./WeChatLoginPanel";
|
import WeChatLoginPanel from "./WeChatLoginPanel";
|
||||||
const FaceRecognitionCommonModal = lazy(() => import("../common/modal/FaceRecognitionCommonModal"));
|
const FaceRecognitionCommonModal = lazy(() => import("../common/modal/FaceRecognitionCommonModal"));
|
||||||
const FaceRecognitionModal = lazy(() => import("../common/modal/FaceRecognitionModal"));
|
const FaceRecognitionModal = lazy(() => import("../common/modal/FaceRecognitionModal"));
|
||||||
@@ -503,7 +503,8 @@ class LoginPage extends React.Component {
|
|||||||
.then((res) => {
|
.then((res) => {
|
||||||
const loginHandler = (res) => {
|
const loginHandler = (res) => {
|
||||||
const responseType = values["type"];
|
const responseType = values["type"];
|
||||||
|
const responseTypes = responseType.split(" ");
|
||||||
|
const responseMode = oAuthParams?.responseMode || "query";
|
||||||
if (responseType === "login") {
|
if (responseType === "login") {
|
||||||
if (res.data3) {
|
if (res.data3) {
|
||||||
sessionStorage.setItem("signinUrl", window.location.pathname + window.location.search);
|
sessionStorage.setItem("signinUrl", window.location.pathname + window.location.search);
|
||||||
@@ -518,14 +519,24 @@ class LoginPage extends React.Component {
|
|||||||
this.setState({
|
this.setState({
|
||||||
userCodeStatus: "success",
|
userCodeStatus: "success",
|
||||||
});
|
});
|
||||||
} else if (responseType === "token" || responseType === "id_token") {
|
} else if (responseTypes.includes("token") || responseTypes.includes("id_token")) {
|
||||||
if (res.data3) {
|
if (res.data3) {
|
||||||
sessionStorage.setItem("signinUrl", window.location.pathname + window.location.search);
|
sessionStorage.setItem("signinUrl", window.location.pathname + window.location.search);
|
||||||
Setting.goToLinkSoft(this, `/forget/${this.state.applicationName}`);
|
Setting.goToLinkSoft(this, `/forget/${this.state.applicationName}`);
|
||||||
}
|
}
|
||||||
const amendatoryResponseType = responseType === "token" ? "access_token" : responseType;
|
const amendatoryResponseType = responseType === "token" ? "access_token" : responseType;
|
||||||
const accessToken = res.data;
|
const accessToken = res.data;
|
||||||
Setting.goToLink(`${oAuthParams.redirectUri}#${amendatoryResponseType}=${accessToken}&state=${oAuthParams.state}&token_type=bearer`);
|
if (responseMode === "form_post") {
|
||||||
|
const params = {
|
||||||
|
token: responseTypes.includes("token") ? res.data : null,
|
||||||
|
id_token: responseTypes.includes("id_token") ? res.data : null,
|
||||||
|
token_type: "bearer",
|
||||||
|
state: oAuthParams?.state,
|
||||||
|
};
|
||||||
|
createFormAndSubmit(oAuthParams?.redirectUri, params);
|
||||||
|
} else {
|
||||||
|
Setting.goToLink(`${oAuthParams.redirectUri}#${amendatoryResponseType}=${accessToken}&state=${oAuthParams.state}&token_type=bearer`);
|
||||||
|
}
|
||||||
} else if (responseType === "saml") {
|
} else if (responseType === "saml") {
|
||||||
if (res.data === RequiredMfa) {
|
if (res.data === RequiredMfa) {
|
||||||
this.props.onLoginSuccess(window.location.href);
|
this.props.onLoginSuccess(window.location.href);
|
||||||
|
Reference in New Issue
Block a user