Skip to content

Commit

Permalink
fix: fix bugs about 3rd-party login in cas flow (casdoor#1096)
Browse files Browse the repository at this point in the history
  • Loading branch information
ComradeProgrammer authored Sep 5, 2022
1 parent 7599e27 commit d8b60f8
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions web/src/auth/AuthCallback.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,12 @@ class AuthCallback extends React.Component {
// Casdoor's own login page, so "code" is not necessary
if (realRedirectUri === null) {
const samlRequest = innerParams.get("SAMLRequest");
// cas don't use 'redirect_url', it is called 'service'
const casService = innerParams.get("service");
if (samlRequest !== null && samlRequest !== undefined && samlRequest !== "") {
return "saml";
} else if (casService !== null && casService !== undefined && casService !== "") {
return "cas";
}
return "login";
}
Expand Down Expand Up @@ -97,6 +101,7 @@ class AuthCallback extends React.Component {
const providerName = innerParams.get("provider");
const method = innerParams.get("method");
const samlRequest = innerParams.get("SAMLRequest");
const casService = innerParams.get("service");

const redirectUri = `${window.location.origin}/callback`;

Expand All @@ -111,6 +116,31 @@ class AuthCallback extends React.Component {
redirectUri: redirectUri,
method: method,
};

if (this.getResponseType() === "cas") {
// user is using casdoor as cas sso server, and wants the ticket to be acquired
AuthBackend.loginCas(body, {"service": casService}).then((res) => {
if (res.status === "ok") {
let msg = "Logged in successfully.";
if (casService === "") {
// If service was not specified, Casdoor must display a message notifying the client that it has successfully initiated a single sign-on session.
msg += "Now you can visit apps protected by Casdoor.";
}
Util.showMessage("success", msg);

if (casService !== "") {
const st = res.data;
const newUrl = new URL(casService);
newUrl.searchParams.append("ticket", st);
window.location.href = newUrl.toString();
}
} else {
Util.showMessage("error", `Failed to log in: ${res.msg}`);
}
});
return;
}
// OAuth
const oAuthParams = Util.getOAuthGetParameters(innerParams);
const concatChar = oAuthParams?.redirectUri?.includes("?") ? "&" : "?";
AuthBackend.login(body, oAuthParams)
Expand Down

0 comments on commit d8b60f8

Please sign in to comment.