Skip to content

Commit

Permalink
fix: web client login
Browse files Browse the repository at this point in the history
  • Loading branch information
darkskygit committed Nov 28, 2024
1 parent dc30e08 commit 91040f2
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 10 deletions.
3 changes: 1 addition & 2 deletions packages/backend/server/src/plugins/oauth/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,6 @@ export class OAuthController {
// we only cache the code and access token in server side
const authState = await this.oauth.getOAuthState(oAuthToken);
if (!authState || authState.state !== inAppState || !authState.code) {
console.log('authState', authState, 'inAppState', inAppState);
throw new OauthStateExpired();
}

Expand All @@ -238,7 +237,7 @@ export class OAuthController {

// NOTE: in web client, we don't need to exchange token
// and provide the auth code directly
const tokens = await provider.getToken(code || authState.code);
const tokens = await provider.getToken(authState.code);
const externAccount = await provider.getUser(tokens.accessToken);
const user = await this.loginFromOauth(
authState.provider,
Expand Down
11 changes: 4 additions & 7 deletions packages/frontend/core/src/desktop/pages/auth/oauth-callback.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const LoaderData = z.object({

const ParsedState = z.object({
payload: LoaderData,
client: supportedClient,
client: supportedClient.optional(),
});

type LoaderData = z.infer<typeof LoaderData>;
Expand All @@ -38,16 +38,13 @@ async function parseState(url: string): Promise<ParsedState> {
return ParsedState.parse({ payload: { state, code, provider }, client });
} catch {}
// new client behavior
const {
token: state,
provider,
client,
} = await fetch('/api/oauth/exchangeToken', {
const { token, provider, client } = await fetch('/api/oauth/exchangeToken', {
method: 'POST',
body: JSON.stringify({ code, state: stateStr }),
headers: { 'content-type': 'application/json' },
}).then(r => r.json());
return ParsedState.parse({ payload: { state, provider }, client });
const payload = client ? { token } : { code, state: stateStr };
return ParsedState.parse({ payload: { ...payload, provider }, client });
}

export const loader: LoaderFunction = async args => {
Expand Down
2 changes: 1 addition & 1 deletion packages/frontend/core/src/modules/cloud/services/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ export class AuthService extends Service {
try {
const res = await this.fetchService.fetch('/api/oauth/callback', {
method: 'POST',
body: JSON.stringify({ code, state, secret: this.state }),
body: JSON.stringify({ code, state }),
headers: {
'content-type': 'application/json',
},
Expand Down

0 comments on commit 91040f2

Please sign in to comment.