Commit 0676365d authored by Chunchi Che's avatar Chunchi Che

try sso login

parent ae3bfdce
Pipeline #22771 passed with stages
in 9 minutes and 44 seconds
......@@ -8,6 +8,7 @@ const WaitRoom = React.lazy(() => import("./WaitRoom"));
const Mora = React.lazy(() => import("./Mora"));
const NeosDuel = React.lazy(() => import("./Duel/Main"));
const Replay = React.lazy(() => import("./Replay"));
const SSO = React.lazy(() => import("./Sso"));
export default function () {
return (
......@@ -45,6 +46,14 @@ export default function () {
</Suspense>
}
/>
<Route
path="/sso/*"
element={
<Suspense fallback={<Loading />}>
<SSO />
</Suspense>
}
/>
</Routes>
);
}
import React, { useEffect } from "react";
interface SSOParams {
id: string;
username: string;
name: string;
email: string;
return_sso_url: string;
token: string;
}
const Sso: React.FC = () => {
const sso = new URL(location.href).searchParams.get("sso");
const ssoParams: SSOParams | undefined = sso
? getSSOParams(new URLSearchParams(atob(sso)))
: undefined;
useEffect(() => {
if (!sso) {
const ssoUrl = getSSOUrl(location.href);
window.location.href = ssoUrl;
}
}, []);
return (
<div>
<p>username={ssoParams?.username}</p>
<p>name={ssoParams?.name}</p>
<p>email={ssoParams?.email}</p>
</div>
);
};
function getSSOUrl(callbackUrl: string): string {
let params = new URLSearchParams();
params.set("return_sso_url", callbackUrl);
const payload = btoa(params.toString());
const url = new URL("https://accounts.moecube.com");
params = url.searchParams;
params.set("sso", payload);
return url.toString();
}
function getSSOParams(searchParams: URLSearchParams): SSOParams {
const sso = {};
for (const [key, value] of searchParams) {
// @ts-ignore
sso[key] = value;
}
return sso as any;
}
export default Sso;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment