Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Update Authorization Prompt URL to Use URL Anchor Instead of Query Parameters (WPB-1343) #15844

Merged
merged 8 commits into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/script/auth/page/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ const LoginComponent = ({
const [verificationCode, setVerificationCode] = useState('');
const [twoFactorSubmitFailedOnce, setTwoFactorSubmitFailedOnce] = useState(false);

const isOauth = UrlUtil.hasURLParameter(QUERY_KEY.SCOPE);
const isOauth = UrlUtil.hasURLParameter(QUERY_KEY.SCOPE, window.location.hash);

const [showEntropyForm, setShowEntropyForm] = useState(false);
const isEntropyRequired = Config.getConfig().FEATURE.ENABLE_EXTRA_CLIENT_ENTROPY;
Expand Down Expand Up @@ -182,7 +182,7 @@ const LoginComponent = ({
await doInitializeClient(ClientType.PERMANENT, undefined, undefined, entropyData);

if (isOauth) {
return navigate(ROUTE.AUTHORIZE);
return navigate(`${ROUTE.AUTHORIZE}/${window.location.hash}`);
}
return navigate(ROUTE.HISTORY_INFO);
} catch (error) {
Expand All @@ -206,7 +206,7 @@ const LoginComponent = ({
await doLogin(login, getEntropy);

if (isOauth) {
return navigate(ROUTE.AUTHORIZE);
return navigate(`${ROUTE.AUTHORIZE}/${window.location.hash}`);
}
return navigate(ROUTE.HISTORY_INFO);
} catch (error) {
Expand Down
15 changes: 14 additions & 1 deletion src/script/auth/page/Root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,20 @@ const RootComponent: FC<RootProps & ConnectedProps & DispatchProps> = ({
};

const isAuthenticatedCheck = (page: any): any => (page ? (isAuthenticated ? page : navigate('/auth')) : null);
const isOAuthCheck = (page: any): any => (page ? isAuthenticated ? page : <Navigate to={ROUTE.LOGIN} /> : null);
const isOAuthCheck = (page: any): any => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't know this type?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't know, its been like this forever

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (page) {
if (isAuthenticated) {
return page;
}

if (window.location.hash.startsWith('#/authorize/#/login')) {
return <Navigate to={window.location.hash.replace('#/authorize/#', '')} />;
}

return <Navigate to={ROUTE.LOGIN} />;
}
return null;
};

const ProtectedHistoryInfo = () => isAuthenticatedCheck(<HistoryInfo />);
const ProtectedInitialInvite = () => isAuthenticatedCheck(<InitialInvite />);
Expand Down
6 changes: 5 additions & 1 deletion src/script/auth/util/oauthUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ import {Scope} from '../page/OAuthPermissions';
* @returns OAuthBody
*/
export const oAuthParams = (location: Location) => {
const params = new URLSearchParams(location.search);
const params = new URLSearchParams(
location.hash.startsWith('#/authorize/#/login?')
? location.hash.replace('#/authorize/#/login?', '')
: location.hash,
);
return Object.fromEntries(params) as unknown as OAuthBody;
};

Expand Down
Loading