2021-08-04 06:48:57 +00:00
|
|
|
import React from 'react';
|
|
|
|
import { BrowserRouter } from 'react-router-dom';
|
|
|
|
import { AuthorizerProvider } from '@authorizerdev/authorizer-react';
|
|
|
|
import Root from './Root';
|
2022-03-09 04:40:39 +00:00
|
|
|
import { createRandomString } from './utils/common';
|
2021-08-04 06:48:57 +00:00
|
|
|
|
2022-09-10 05:53:20 +00:00
|
|
|
declare global {
|
|
|
|
interface Window {
|
|
|
|
__authorizer__: any;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-04 06:48:57 +00:00
|
|
|
export default function App() {
|
2022-03-09 04:40:39 +00:00
|
|
|
const searchParams = new URLSearchParams(window.location.search);
|
|
|
|
const state = searchParams.get('state') || createRandomString();
|
|
|
|
const scope = searchParams.get('scope')
|
|
|
|
? searchParams.get('scope')?.toString().split(' ')
|
|
|
|
: `openid profile email`;
|
|
|
|
|
|
|
|
const urlProps: Record<string, any> = {
|
|
|
|
state,
|
|
|
|
scope,
|
|
|
|
};
|
|
|
|
|
|
|
|
const redirectURL =
|
|
|
|
searchParams.get('redirect_uri') || searchParams.get('redirectURL');
|
|
|
|
if (redirectURL) {
|
|
|
|
urlProps.redirectURL = redirectURL;
|
|
|
|
} else {
|
2022-03-15 04:26:50 +00:00
|
|
|
urlProps.redirectURL = window.location.origin + '/app';
|
2022-03-09 04:40:39 +00:00
|
|
|
}
|
|
|
|
const globalState: Record<string, string> = {
|
|
|
|
...window['__authorizer__'],
|
|
|
|
...urlProps,
|
|
|
|
};
|
|
|
|
|
2021-10-03 21:47:50 +00:00
|
|
|
return (
|
|
|
|
<div
|
|
|
|
style={{
|
|
|
|
display: 'flex',
|
|
|
|
justifyContent: 'center',
|
|
|
|
flexDirection: 'column',
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<div
|
|
|
|
style={{
|
|
|
|
display: 'flex',
|
|
|
|
justifyContent: 'center',
|
|
|
|
marginTop: 20,
|
|
|
|
flexDirection: 'column',
|
|
|
|
alignItems: 'center',
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<img
|
|
|
|
src={`${globalState.organizationLogo}`}
|
|
|
|
alt="logo"
|
|
|
|
style={{ height: 60, width: 60, objectFit: 'cover' }}
|
|
|
|
/>
|
|
|
|
<h1>{globalState.organizationName}</h1>
|
|
|
|
</div>
|
2022-03-08 07:06:26 +00:00
|
|
|
<div className="container">
|
2021-10-03 21:47:50 +00:00
|
|
|
<BrowserRouter>
|
|
|
|
<AuthorizerProvider
|
|
|
|
config={{
|
2022-01-17 06:02:13 +00:00
|
|
|
authorizerURL: window.location.origin,
|
2021-10-03 21:47:50 +00:00
|
|
|
redirectURL: globalState.redirectURL,
|
|
|
|
}}
|
|
|
|
>
|
2022-03-09 04:40:39 +00:00
|
|
|
<Root globalState={globalState} />
|
2021-10-03 21:47:50 +00:00
|
|
|
</AuthorizerProvider>
|
|
|
|
</BrowserRouter>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
2021-08-04 06:48:57 +00:00
|
|
|
}
|