fix(core): strict client oauth parameters check (#8159)

This commit is contained in:
forehalo
2024-09-08 12:44:47 +00:00
parent 63e1fce3ca
commit 57083905ff
6 changed files with 69 additions and 25 deletions
@@ -1,9 +1,11 @@
import { Skeleton } from '@affine/component';
import { Button } from '@affine/component/ui/button';
import { popupWindow } from '@affine/core/utils';
import { appInfo } from '@affine/electron-api';
import { OAuthProviderType } from '@affine/graphql';
import { GithubIcon, GoogleDuotoneIcon } from '@blocksuite/icons/rc';
import { useLiveData, useService } from '@toeverything/infra';
import type { ReactElement } from 'react';
import { type ReactElement, useCallback } from 'react';
import { ServerConfigService } from '../../../modules/cloud';
@@ -46,25 +48,29 @@ export function OAuth() {
function OAuthProvider({ provider }: { provider: OAuthProviderType }) {
const { icon } = OAuthProviderMap[provider];
const onClick = useCallback(() => {
let oauthUrl =
(environment.isElectron ? runtimeConfig.serverUrlPrefix : '') +
`/oauth/login?provider=${provider}`;
if (environment.isElectron) {
oauthUrl += `&client=${appInfo?.schema}`;
}
popupWindow(oauthUrl);
}, [provider]);
return (
<a
href={
(environment.isDesktopEdition ? runtimeConfig.serverUrlPrefix : '') +
`/oauth/login?provider=${provider}`
}
target="_blank"
rel="noreferrer"
<Button
key={provider}
variant="primary"
block
size="extraLarge"
style={{ marginTop: 30, width: '100%' }}
prefix={icon}
onClick={onClick}
>
<Button
key={provider}
variant="primary"
block
size="extraLarge"
style={{ marginTop: 30, width: '100%' }}
prefix={icon}
>
Continue with {provider}
</Button>
</a>
Continue with {provider}
</Button>
);
}