Skip to content

Commit 64699e3

Browse files
committed
fix(v1): google use different callbacks to get token (#768)
1 parent 7cbc912 commit 64699e3

File tree

6 files changed

+17
-6
lines changed

6 files changed

+17
-6
lines changed

config/defaults.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ login:
100100
client_id:
101101
client_secret:
102102
redirect_uri:
103+
login:
104+
bind:
103105
apple:
104106
enable: false
105107
agora:

config/test.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ login:
9595
client_id:
9696
client_secret:
9797
redirect_uri:
98+
login:
99+
bind:
98100
apple:
99101
enable: true
100102
agora:

src/utils/ParseConfig.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,10 @@ type Config = {
115115
enable: boolean;
116116
client_id: string;
117117
client_secret: string;
118-
redirect_uri: string;
118+
redirect_uri: {
119+
login: string;
120+
bind: string;
121+
};
119122
};
120123
apple: {
121124
enable: boolean;

src/v1/controller/login/google/Callback.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export class GoogleCallback extends AbstractController<RequestType> {
4848

4949
await LoginGoogle.assertHasAuthUUID(authUUID, this.logger);
5050

51-
const userInfo = await LoginGoogle.getUserInfoAndToken(code);
51+
const userInfo = await LoginGoogle.getUserInfoAndToken("login", code);
5252

5353
const userUUIDByDB = await ServiceUserGoogle.userUUIDByUnionUUID(userInfo.unionUUID);
5454

src/v1/controller/login/platforms/LoginGoogle.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,17 @@ export class LoginGoogle extends AbstractLogin {
3131
});
3232
}
3333

34-
public static async getToken(code: string): Promise<string> {
34+
public static async getToken(
35+
route: keyof typeof Google.redirectURI,
36+
code: string,
37+
): Promise<string> {
3538
const response = await ax.post<AccessToken>(
3639
"https://oauth2.googleapis.com/token",
3740
new URLSearchParams({
3841
code,
3942
client_id: Google.clientId,
4043
client_secret: Google.clientSecret,
41-
redirect_uri: Google.redirectURI,
44+
redirect_uri: Google.redirectURI[route],
4245
grant_type: "authorization_code",
4346
}),
4447
);
@@ -68,9 +71,10 @@ export class LoginGoogle extends AbstractLogin {
6871
}
6972

7073
public static async getUserInfoAndToken(
74+
route: keyof typeof Google.redirectURI,
7175
code: string,
7276
): Promise<GoogleUserInfo & { accessToken: string }> {
73-
const accessToken = await LoginGoogle.getToken(code);
77+
const accessToken = await LoginGoogle.getToken(route, code);
7478
const userInfo = await LoginGoogle.getUserInfoByAPI(accessToken);
7579

7680
return {

src/v1/controller/user/binding/platform/google/Binding.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export class BindingGoogle extends AbstractController<RequestType, any> {
5959
throw new ControllerError(ErrorCode.UnsupportedOperation);
6060
}
6161

62-
const userInfo = await LoginGoogle.getUserInfoAndToken(code);
62+
const userInfo = await LoginGoogle.getUserInfoAndToken("bind", code);
6363
const userUUIDByDB = await ServiceUserGoogle.userUUIDByUnionUUID(userInfo.unionUUID);
6464
if (userUUIDByDB) {
6565
throw new ControllerError(ErrorCode.UserAlreadyBinding);

0 commit comments

Comments
 (0)