Skip to content

Commit e7bd611

Browse files
committed
fix(comment): fix comments
1 parent 2785895 commit e7bd611

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

src/auth/social.service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ export class SocialService {
2929
}
3030
}
3131

32-
protected setState(type: string) {
33-
const state = generateId();
32+
protected setState(type: string, prefix: string = '') {
33+
const state = `${prefix ? prefix + '' : ''}${generateId()}`;
3434
this.states.set(state, {
3535
type,
3636
createdAt: Date.now(),

src/auth/wechat/wechat.service.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ export class WechatService extends SocialService {
203203

204204
migrationQrCode(type: 'new' | 'old' = 'new') {
205205
const isOld = type === 'old';
206-
const state = this.setState('open_weixin');
206+
const state = this.setState('open_weixin', type);
207207
this.cleanExpiresState();
208208
return {
209209
state,
@@ -215,7 +215,7 @@ export class WechatService extends SocialService {
215215

216216
migrationAuthUrl(type: 'new' | 'old' = 'new'): string {
217217
const isOld = type === 'old';
218-
const state = this.setState('weixin');
218+
const state = this.setState('weixin', type);
219219
this.cleanExpiresState();
220220
return `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${isOld ? this.oldAppId : this.appId}&redirect_uri=${encodeURIComponent(this.migrationRedirectUri)}&response_type=code&scope=snsapi_userinfo&state=${state}#wechat_redirect`;
221221
}
@@ -228,9 +228,14 @@ export class WechatService extends SocialService {
228228
if (!stateInfo) {
229229
throw new UnauthorizedException('Invalid state identifier');
230230
}
231+
const isOld = state.startsWith('old_');
231232
const isWeixin = stateInfo.type === 'weixin';
232-
const appId = isWeixin ? this.oldAppId : this.oldOpenAppId;
233-
const appSecret = isWeixin ? this.oldAppSecret : this.oldOpenAppSecret;
233+
const rawAppid = isOld ? this.oldAppId : this.appId;
234+
const rawAppsecret = isOld ? this.oldAppSecret : this.appSecret;
235+
const rawOpenAppid = isOld ? this.oldOpenAppId : this.openAppId;
236+
const rawOpenAppsecret = isOld ? this.oldOpenAppSecret : this.openAppSecret;
237+
const appId = isWeixin ? rawAppid : rawOpenAppid;
238+
const appSecret = isWeixin ? rawAppsecret : rawOpenAppsecret;
234239
const accessTokenResponse = await fetch(
235240
`https://api.weixin.qq.com/sns/oauth2/access_token?appid=${appId}&secret=${appSecret}&code=${code}&grant_type=authorization_code`,
236241
);

0 commit comments

Comments
 (0)