aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorGravatar Hassan Abouelela <[email protected]>2021-02-17 09:30:47 +0300
committerGravatar Hassan Abouelela <[email protected]>2021-02-17 09:30:47 +0300
commitfba316f235a3871743427f37b3bbd07bea6d77bd (patch)
treeaf8a53d2677b4b135463899fb271ed127384440e /src
parentCleans Up OAuth Error Logging (diff)
Removes Path From Auth
Signed-off-by: Hassan Abouelela <[email protected]>
Diffstat (limited to 'src')
-rw-r--r--src/api/auth.ts23
-rw-r--r--src/components/OAuth2Button.tsx5
-rw-r--r--src/pages/FormPage.tsx6
3 files changed, 15 insertions, 19 deletions
diff --git a/src/api/auth.ts b/src/api/auth.ts
index ad97e67..cfaa563 100644
--- a/src/api/auth.ts
+++ b/src/api/auth.ts
@@ -91,11 +91,11 @@ function ensureMinimumScopes(scopes: unknown, expected: OAuthScopes | OAuthScope
/**
* Return true if the program has the requested scopes or higher.
*/
-export function checkScopes(scopes?: OAuthScopes[], path = ""): boolean {
+export function checkScopes(scopes?: OAuthScopes[]): boolean {
const cleanedScopes = ensureMinimumScopes(scopes, OAuthScopes.Identify);
// Get Active Scopes And Ensure Type
- const cookies = new Cookies().get(CookieNames.Scopes + path);
+ const cookies = new Cookies().get(CookieNames.Scopes);
if (!cookies || !Array.isArray(cookies)) {
return false;
}
@@ -169,7 +169,7 @@ export async function getDiscordCode(scopes: OAuthScopes[]): Promise<{code: stri
}
/**
- * Sends a discord code from a given path to the backend,
+ * Sends a discord code to the backend,
* and returns the resultant JWT and expiry date.
*
* @throws { APIErrors } On error, the APIErrors.Message is set, and an APIErrors object is thrown.
@@ -218,27 +218,26 @@ export async function requestBackendJWT(code: string): Promise<JWTResponse> {
}
/**
- * Handle a full authorization flow. Sets a token for the specified path with the JWT and scopes.
+ * Handle a full authorization flow. Sets a cookie with the JWT and scopes.
*
* @param scopes The scopes that should be authorized for the application.
* @param disableFunction An optional function that can disable a component while processing.
- * @param path The site path to save the token under.
*
* @throws { APIErrors } See documentation on { requestBackendJWT }.
*/
-export default async function authorize(scopes: OAuthScopes[] = [], disableFunction?: (newState: boolean) => void, path = "/"): Promise<void> {
- if (!checkScopes(scopes, path)) {
+export default async function authorize(scopes: OAuthScopes[] = [], disableFunction?: (newState: boolean) => void): Promise<void> {
+ if (!checkScopes(scopes)) {
const cookies = new Cookies;
- cookies.remove(CookieNames.Token + path);
- cookies.remove(CookieNames.Scopes + path);
+ cookies.remove(CookieNames.Token);
+ cookies.remove(CookieNames.Scopes);
if (disableFunction) { disableFunction(true); }
await getDiscordCode(scopes).then(async discord_response =>{
await requestBackendJWT(discord_response.code).then(backend_response => {
- const options: CookieSetOptions = {sameSite: "strict", expires: backend_response.Expiry, secure: PRODUCTION, path: path};
+ const options: CookieSetOptions = {sameSite: "strict", expires: backend_response.Expiry, secure: PRODUCTION};
- cookies.set(CookieNames.Token + path, backend_response.JWT, options);
- cookies.set(CookieNames.Scopes + path, discord_response.cleanedScopes, options);
+ cookies.set(CookieNames.Token, backend_response.JWT, options);
+ cookies.set(CookieNames.Scopes, discord_response.cleanedScopes, options);
});
}).finally(() => {
if (disableFunction) { disableFunction(false); }
diff --git a/src/components/OAuth2Button.tsx b/src/components/OAuth2Button.tsx
index 1ee456c..25c5871 100644
--- a/src/components/OAuth2Button.tsx
+++ b/src/components/OAuth2Button.tsx
@@ -11,7 +11,6 @@ import { selectable } from "../commonStyles";
interface OAuth2ButtonProps {
scopes?: OAuthScopes[],
- path?: string,
rerender: () => void
}
@@ -47,7 +46,7 @@ const errorStyles = css`
`;
async function login(props: OAuth2ButtonProps, errorDialog: React.RefObject<HTMLDivElement>, setDisabled: (newState: boolean) => void) {
- await authenticate(props.scopes, setDisabled, props.path).catch((reason: APIErrors) => {
+ await authenticate(props.scopes, setDisabled).catch((reason: APIErrors) => {
// Display Error Message
if (errorDialog.current) {
errorDialog.current.style.visibility = "visible";
@@ -60,7 +59,7 @@ async function login(props: OAuth2ButtonProps, errorDialog: React.RefObject<HTML
throw reason.Error;
});
- if (checkScopes(props.scopes, props.path)) {
+ if (checkScopes(props.scopes)) {
props.rerender();
}
}
diff --git a/src/pages/FormPage.tsx b/src/pages/FormPage.tsx
index 4237e86..4e13b8a 100644
--- a/src/pages/FormPage.tsx
+++ b/src/pages/FormPage.tsx
@@ -27,8 +27,6 @@ interface NavigationProps {
}
class Navigation extends React.Component<NavigationProps> {
- PAGE_PATH = "/form"
-
containerStyles = css`
margin: auto;
width: 50%;
@@ -97,9 +95,9 @@ class Navigation extends React.Component<NavigationProps> {
let submit = null;
if (this.props.form_state) {
- if (this.props.scopes.includes(OAuthScopes.Identify) && !checkScopes(this.props.scopes, this.PAGE_PATH)) {
+ if (this.props.scopes.includes(OAuthScopes.Identify) && !checkScopes(this.props.scopes)) {
// Render OAuth button if login is required, and the scopes needed are not available
- submit = <OAuth2Button path={this.PAGE_PATH} scopes={this.props.scopes} rerender={() => this.setState({"logged_in": true})}/>;
+ submit = <OAuth2Button scopes={this.props.scopes} rerender={() => this.setState({"logged_in": true})}/>;
} else {
submit = <button form="form" type="submit">Submit</button>;
}