-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replaced the Grand Central cookie-based login mechanism with a bearer…
… token Instead of relying on Grand Central to specify a cookie, we instead set one ourselves, and then use Grand Central's API to specify the token as an Authorization header.
- Loading branch information
Showing
19 changed files
with
130 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const GRAND_CENTRAL_TOKEN_COOKIE = 'grand_central_token'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import useGcApi from './useGcApi.ts'; | ||
import { apiGet } from '../utils/api.ts'; | ||
import useCookie from 'react-use-cookie'; | ||
import { GRAND_CENTRAL_TOKEN_COOKIE } from '../constants/cookie.ts'; | ||
|
||
export type GCLoginParams = { | ||
token: string; | ||
refresh?: string | null; | ||
}; | ||
export default function useGCLogin() { | ||
const gcApi = useGcApi(); | ||
const [, setToken] = useCookie(GRAND_CENTRAL_TOKEN_COOKIE); | ||
|
||
return async ({ token, refresh }: GCLoginParams) => { | ||
let qs = `?token=${token}`; | ||
if (refresh) { | ||
qs += `&refresh=${refresh}`; | ||
} | ||
try { | ||
const res = await apiGet(gcApi, `/api/auth${qs}`, {}); | ||
if (res.success && res.status == 200) { | ||
setToken(token); | ||
return true; | ||
} | ||
return false; | ||
} catch (e) { | ||
return false; | ||
} | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,5 @@ | ||
import './index.css'; | ||
import { ConnectionStatus } from './utils/gc/connectivity'; | ||
|
||
export * from './components'; | ||
export * from './contexts'; | ||
export * from './routes'; | ||
export { ConnectionStatus }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import useCookie from 'react-use-cookie'; | ||
import { GRAND_CENTRAL_TOKEN_COOKIE } from '../../constants/cookie.ts'; | ||
import { GCSpin, NoDataView } from '../../components'; | ||
import { useMemo, useState } from 'react'; | ||
import useGCLogin from '../../hooks/useGCLogin.ts'; | ||
|
||
function Auth() { | ||
const [, setToken] = useCookie(GRAND_CENTRAL_TOKEN_COOKIE); | ||
|
||
const gcLogin = useGCLogin(); | ||
|
||
const [status, setStatus] = useState<boolean | undefined>(undefined); | ||
|
||
const specifiedToken = new URLSearchParams(location.search).get('token'); | ||
const specifiedRefreshToken = new URLSearchParams(location.search).get('refresh'); | ||
|
||
useMemo(() => { | ||
if (!specifiedToken) { | ||
setStatus(false); | ||
return; | ||
} | ||
gcLogin({ | ||
token: specifiedToken, | ||
refresh: specifiedRefreshToken, | ||
}).then(success => { | ||
if (success) { | ||
setToken(specifiedToken); | ||
setStatus(true); | ||
window.location.assign('/'); | ||
} else { | ||
setStatus(false); | ||
} | ||
}); | ||
}, [specifiedToken]); | ||
|
||
return ( | ||
<GCSpin spinning={status === undefined}> | ||
{status === false && ( | ||
<NoDataView description="Could not authenticate to Grand Central: Invalid or no token" /> | ||
)} | ||
</GCSpin> | ||
); | ||
} | ||
|
||
export default Auth; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import Auth from './Auth'; | ||
|
||
export default Auth; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters