@cloudbase/auth 1.6.1 → 2.0.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/dist/cjs/index.d.ts +50 -96
  2. package/dist/cjs/index.js +411 -679
  3. package/dist/esm/index.d.ts +50 -96
  4. package/dist/esm/index.js +412 -676
  5. package/package.json +52 -54
  6. package/src/index.ts +413 -650
  7. package/dist/cjs/constants.d.ts +0 -11
  8. package/dist/cjs/constants.js +0 -16
  9. package/dist/cjs/providers/anonymousAuthProvider.d.ts +0 -15
  10. package/dist/cjs/providers/anonymousAuthProvider.js +0 -255
  11. package/dist/cjs/providers/base.d.ts +0 -20
  12. package/dist/cjs/providers/base.js +0 -158
  13. package/dist/cjs/providers/customAuthProvider.d.ts +0 -5
  14. package/dist/cjs/providers/customAuthProvider.js +0 -149
  15. package/dist/cjs/providers/emailAuthProvider.d.ts +0 -9
  16. package/dist/cjs/providers/emailAuthProvider.js +0 -248
  17. package/dist/cjs/providers/phoneAuthProvider.d.ts +0 -17
  18. package/dist/cjs/providers/phoneAuthProvider.js +0 -217
  19. package/dist/cjs/providers/usernameAuthProvider.d.ts +0 -5
  20. package/dist/cjs/providers/usernameAuthProvider.js +0 -168
  21. package/dist/cjs/providers/weixinAuthProvider.d.ts +0 -28
  22. package/dist/cjs/providers/weixinAuthProvider.js +0 -294
  23. package/dist/esm/constants.d.ts +0 -11
  24. package/dist/esm/constants.js +0 -13
  25. package/dist/esm/providers/anonymousAuthProvider.d.ts +0 -15
  26. package/dist/esm/providers/anonymousAuthProvider.js +0 -252
  27. package/dist/esm/providers/base.d.ts +0 -20
  28. package/dist/esm/providers/base.js +0 -155
  29. package/dist/esm/providers/customAuthProvider.d.ts +0 -5
  30. package/dist/esm/providers/customAuthProvider.js +0 -146
  31. package/dist/esm/providers/emailAuthProvider.d.ts +0 -9
  32. package/dist/esm/providers/emailAuthProvider.js +0 -245
  33. package/dist/esm/providers/phoneAuthProvider.d.ts +0 -17
  34. package/dist/esm/providers/phoneAuthProvider.js +0 -214
  35. package/dist/esm/providers/usernameAuthProvider.d.ts +0 -5
  36. package/dist/esm/providers/usernameAuthProvider.js +0 -165
  37. package/dist/esm/providers/weixinAuthProvider.d.ts +0 -28
  38. package/dist/esm/providers/weixinAuthProvider.js +0 -291
  39. package/src/constants.ts +0 -11
  40. package/src/providers/anonymousAuthProvider.ts +0 -125
  41. package/src/providers/base.ts +0 -66
  42. package/src/providers/customAuthProvider.ts +0 -68
  43. package/src/providers/emailAuthProvider.ts +0 -139
  44. package/src/providers/phoneAuthProvider.ts +0 -130
  45. package/src/providers/usernameAuthProvider.ts +0 -76
  46. package/src/providers/weixinAuthProvider.ts +0 -193
@@ -1,139 +0,0 @@
1
- import { constants,utils,helpers } from '@cloudbase/utilities';
2
- import { ILoginState } from '@cloudbase/types/auth';
3
- import { AuthProvider } from './base';
4
- import { LOGINTYPE } from '../constants';
5
- import { eventBus, EVENTS, LoginState } from '..';
6
-
7
- const { throwError, isString } = utils;
8
- const { ERRORS, COMMUNITY_SITE_URL } = constants;
9
- const { catchErrorsDecorator } = helpers;
10
-
11
- export class EmailAuthProvider extends AuthProvider {
12
- @catchErrorsDecorator({
13
- title: '邮箱密码登录失败',
14
- messages: [
15
- '请确认以下各项:',
16
- ' 1 - 调用 auth().emailAuthProvider() 的语法或参数是否正确',
17
- ' 2 - 当前环境是否开通了邮箱登录',
18
- ' 3 - 邮箱地址与密码是否匹配',
19
- `如果问题依然存在,建议到官方问答社区提问或寻找帮助:${COMMUNITY_SITE_URL}`
20
- ]
21
- })
22
- public async signIn(email: string, password: string): Promise<ILoginState> {
23
- if (!isString(email)) {
24
- throwError(ERRORS.INVALID_PARAMS,'email must be a string');
25
- }
26
- const { refreshTokenKey } = this._cache.keys;
27
- const res = await this._request.send('auth.signIn', {
28
- loginType: 'EMAIL',
29
- email,
30
- password,
31
- refresh_token: this._cache.getStore(refreshTokenKey) || ''
32
- });
33
- const { refresh_token, access_token, access_token_expire } = res;
34
- if (refresh_token) {
35
- await this.setRefreshToken(refresh_token);
36
- if (access_token && access_token_expire) {
37
- await this.setAccessToken(access_token, access_token_expire);
38
- } else {
39
- await this._request.refreshAccessToken();
40
- }
41
- // set user info
42
- await this.refreshUserInfo();
43
- eventBus.fire(EVENTS.LOGIN_STATE_CHANGED);
44
- eventBus.fire(EVENTS.LOGIN_TYPE_CHANGED, {
45
- env: this._config.env,
46
- loginType: LOGINTYPE.EMAIL,
47
- persistence: this._config.persistence
48
- });
49
- return new LoginState({
50
- envId: this._config.env,
51
- cache: this._cache,
52
- request: this._request
53
- });
54
- } else if (res.code) {
55
- throwError(ERRORS.OPERATION_FAIL,`Email login fail[${res.code}] ${res.message}`);
56
- } else {
57
- throwError(ERRORS.OPERATION_FAIL,`Email login fail`);
58
- }
59
- }
60
- /**
61
- * 注册
62
- * @param email
63
- * @param password
64
- */
65
- @catchErrorsDecorator({
66
- title: '邮箱注册失败',
67
- messages: [
68
- '请确认以下各项:',
69
- ' 1 - 调用 auth().signUpWithEmailAndPassword() 的语法或参数是否正确',
70
- ' 2 - 当前环境是否开通了邮箱登录',
71
- ' 3 - 此邮箱地址是否已经被其他用户占用',
72
- `如果问题依然存在,建议到官方问答社区提问或寻找帮助:${COMMUNITY_SITE_URL}`
73
- ]
74
- })
75
- public async signUp(email:string, password:string) {
76
- return this._request.send('auth.signUpWithEmailAndPassword', {
77
- email,
78
- password
79
- });
80
- }
81
- /**
82
- * 发起重置密码请求,发起后推送邮件到指定邮箱
83
- * @param email
84
- */
85
- @catchErrorsDecorator({
86
- title: '重置密码失败',
87
- messages: [
88
- '请确认以下各项:',
89
- ' 1 - 调用 auth().sendPasswordResetEmail() 的语法或参数是否正确',
90
- ' 2 - 当前环境是否开通了邮箱登录',
91
- ' 3 - 此邮箱地址是否已经与当前用户绑定',
92
- ' 4 - 此邮箱地址是否已经被其他用户占用',
93
- `如果问题依然存在,建议到官方问答社区提问或寻找帮助:${COMMUNITY_SITE_URL}`
94
- ]
95
- })
96
- public async resetPassword(email:string) {
97
- return this._request.send('auth.sendPasswordResetEmail', {
98
- email
99
- });
100
- }
101
- /**
102
- * 重置密码
103
- * @param token
104
- * @param newPassword
105
- */
106
- @catchErrorsDecorator({
107
- title: '重置密码失败',
108
- messages: [
109
- '请确认以下各项:',
110
- ' 1 - 调用语法或参数是否正确',
111
- ' 2 - 当前环境是否开通了邮箱登录',
112
- `如果问题依然存在,建议到官方问答社区提问或寻找帮助:${COMMUNITY_SITE_URL}`
113
- ]
114
- })
115
- public async resetPasswordWithToken(token:string, newPassword:string) {
116
- return this._request.send('auth.resetPasswordWithToken', {
117
- token,
118
- newPassword
119
- });
120
- }
121
- /**
122
- * 激活邮箱
123
- * @param token
124
- */
125
- @catchErrorsDecorator({
126
- title: '邮箱激活失败',
127
- messages: [
128
- '请确认以下各项:',
129
- ' 1 - 调用语法或参数是否正确',
130
- ' 2 - 当前环境是否开通了邮箱登录',
131
- `如果问题依然存在,建议到官方问答社区提问或寻找帮助:${COMMUNITY_SITE_URL}`
132
- ]
133
- })
134
- public async activate(token: string) {
135
- return this._request.send('auth.activateEndUserMail', {
136
- token
137
- });
138
- }
139
- }
@@ -1,130 +0,0 @@
1
- import { constants, utils, helpers } from '@cloudbase/utilities';
2
- import { ILoginState } from '@cloudbase/types/auth';
3
- import { AuthProvider } from './base';
4
- import { LOGINTYPE } from '../constants';
5
- import { eventBus, EVENTS, LoginState } from '..';
6
-
7
- const { throwError, isString, transformPhone } = utils;
8
- const { ERRORS, COMMUNITY_SITE_URL } = constants;
9
- const { catchErrorsDecorator } = helpers;
10
-
11
- export const SIGN_METHOD = {
12
- SIGNIN: 'SIGNIN',
13
- SIGNUP: 'SIGNUP',
14
- FORCERESETPWD: 'FORCERESETPWD'
15
- }
16
-
17
- export class PhoneAuthProvider extends AuthProvider {
18
- @catchErrorsDecorator({
19
- title: '手机号登录失败',
20
- messages: [
21
- '请确认以下各项:',
22
- ' 1 - 调用 auth().SmsAuthProvider() 的语法或参数是否正确',
23
- ' 2 - 当前环境是否开通了短信验证码登录',
24
- ' 3 - 短信验证码/密码是否正确',
25
- `如果问题依然存在,建议到官方问答社区提问或寻找帮助:${COMMUNITY_SITE_URL}`
26
- ]
27
- })
28
- public async signIn(param: {
29
- phoneNumber: string
30
- phoneCode?: string
31
- password?: string
32
- signMethod?: string
33
- }): Promise<ILoginState> {
34
- let { phoneNumber, phoneCode, password, signMethod } = param
35
- if (!isString(phoneNumber)) {
36
- throwError(ERRORS.INVALID_PARAMS, 'phoneNumber must be a string');
37
- }
38
-
39
- if (!isString(phoneCode) && !isString(password)) {
40
- throwError(ERRORS.INVALID_PARAMS, 'phoneCode or password must be a string');
41
- }
42
-
43
- if (!signMethod) {
44
- signMethod = SIGN_METHOD.SIGNIN
45
- }
46
-
47
- const { refreshTokenKey } = this._cache.keys;
48
- const res = await this._request.send('auth.signIn', {
49
- loginType: LOGINTYPE.PHONE,
50
- phoneNumber: transformPhone(phoneNumber),
51
- phoneCode,
52
- password,
53
- refresh_token: this._cache.getStore(refreshTokenKey) || '',
54
- signMethod
55
- });
56
- const { refresh_token, access_token, access_token_expire } = res;
57
- if (refresh_token) {
58
- await this.setRefreshToken(refresh_token);
59
- if (access_token && access_token_expire) {
60
- await this.setAccessToken(access_token, access_token_expire);
61
- } else {
62
- await this._request.refreshAccessToken();
63
- }
64
- // set user info
65
- await this.refreshUserInfo();
66
- eventBus.fire(EVENTS.LOGIN_STATE_CHANGED);
67
- eventBus.fire(EVENTS.LOGIN_TYPE_CHANGED, {
68
- env: this._config.env,
69
- loginType: LOGINTYPE.PHONE,
70
- persistence: this._config.persistence
71
- });
72
- return new LoginState({
73
- envId: this._config.env,
74
- cache: this._cache,
75
- request: this._request
76
- });
77
- } else if (res.code) {
78
- throwError(ERRORS.OPERATION_FAIL, `Phone login fail[${res.code}] ${res.message}`);
79
- } else {
80
- throwError(ERRORS.OPERATION_FAIL, `Phone login fail`);
81
- }
82
- }
83
- /**
84
- * 手机号注册
85
- * @param phoneNumber
86
- * @param phoneCode
87
- * @param password
88
- */
89
- @catchErrorsDecorator({
90
- title: '手机短信注册失败',
91
- messages: [
92
- '请确认以下各项:',
93
- ' 1 - 调用 auth().signUpWithPhoneCode() 的语法或参数是否正确',
94
- ' 2 - 当前环境是否开通了短信验证码登录',
95
- `如果问题依然存在,建议到官方问答社区提问或寻找帮助:${COMMUNITY_SITE_URL}`
96
- ]
97
- })
98
- public async signUp(phoneNumber: string, phoneCode: string, password?: string): Promise<ILoginState> {
99
- return this.signIn({
100
- phoneNumber,
101
- phoneCode,
102
- password,
103
- signMethod: SIGN_METHOD.SIGNUP
104
- })
105
- }
106
-
107
- /**
108
- * 手机号注册
109
- * @param phoneNumber
110
- * @param phoneCode
111
- * @param password
112
- */
113
- @catchErrorsDecorator({
114
- title: '手机密码重置失败',
115
- messages: [
116
- '请确认以下各项:',
117
- ' 1 - 调用 auth().forceResetPwd() 的语法或参数是否正确',
118
- ' 2 - 当前环境是否开通了短信验证码登录',
119
- `如果问题依然存在,建议到官方问答社区提问或寻找帮助:${COMMUNITY_SITE_URL}`
120
- ]
121
- })
122
- public async forceResetPwd(phoneNumber: string, phoneCode: string, password: string): Promise<ILoginState> {
123
- return this.signIn({
124
- phoneNumber,
125
- phoneCode,
126
- password,
127
- signMethod: SIGN_METHOD.FORCERESETPWD
128
- })
129
- }
130
- }
@@ -1,76 +0,0 @@
1
- import { AuthProvider } from './base';
2
- import { ILoginState } from '@cloudbase/types/auth';
3
- import { eventBus, EVENTS, LoginState } from '..';
4
- import { LOGINTYPE } from '../constants';
5
- import { utils, constants, helpers } from '@cloudbase/utilities';
6
-
7
- const { printWarn } = utils;
8
- const { ERRORS, COMMUNITY_SITE_URL } = constants;
9
- const { catchErrorsDecorator } = helpers;
10
-
11
- export class UsernameAuthProvider extends AuthProvider {
12
- @catchErrorsDecorator({
13
- title: '用户名密码登录失败',
14
- messages: [
15
- '请确认以下各项:',
16
- ' 1 - 调用 auth().signInWithUsernameAndPassword() 的语法或参数是否正确',
17
- ' 2 - 当前环境是否开通了用户名密码登录',
18
- ' 3 - 用户名密码是否匹配',
19
- `如果问题依然存在,建议到官方问答社区提问或寻找帮助:${COMMUNITY_SITE_URL}`
20
- ]
21
- })
22
- public async signIn(username: string, password: string): Promise<ILoginState> {
23
- if (typeof username !== 'string') {
24
- throw new Error(JSON.stringify({
25
- code: ERRORS.INVALID_PARAMS,
26
- msg: 'username must be a string'
27
- }));
28
- }
29
- // 用户不设置密码
30
- if (typeof password !== 'string') {
31
- password = '';
32
- printWarn(ERRORS.INVALID_PARAMS,'password is empty');
33
- }
34
-
35
- const { refreshTokenKey } = this._cache.keys;
36
- const res = await this._request.send('auth.signIn',{
37
- loginType: LOGINTYPE.USERNAME,
38
- username,
39
- password,
40
- refresh_token: await this._cache.getStoreAsync(refreshTokenKey) || ''
41
- });
42
-
43
- const { refresh_token, access_token_expire, access_token } = res;
44
- if (refresh_token) {
45
- await this.setRefreshToken(refresh_token);
46
- if (access_token && access_token_expire) {
47
- await this.setAccessToken(access_token, access_token_expire);
48
- } else {
49
- await this._request.refreshAccessToken();
50
- }
51
- // set user info
52
- await this.refreshUserInfo();
53
- eventBus.fire(EVENTS.LOGIN_STATE_CHANGED);
54
- eventBus.fire(EVENTS.LOGIN_TYPE_CHANGED, {
55
- env: this._config.env,
56
- loginType: LOGINTYPE.USERNAME,
57
- persistence: this._config.persistence
58
- });
59
- return new LoginState({
60
- envId: this._config.env,
61
- cache: this._cache,
62
- request: this._request
63
- });
64
- } else if (res.code) {
65
- throw new Error(JSON.stringify({
66
- code: ERRORS.OPERATION_FAIL,
67
- msg: `login by username failed:[${res.code}] ${res.message}`
68
- }));
69
- } else {
70
- throw new Error(JSON.stringify({
71
- code: ERRORS.OPERATION_FAIL,
72
- msg: 'login by username failed'
73
- }));
74
- }
75
- }
76
- }
@@ -1,193 +0,0 @@
1
- import { AuthProvider } from './base';
2
- import { ICloudbaseAuthConfig } from '@cloudbase/types/auth';
3
- import { ICloudbaseCache } from '@cloudbase/types/cache';
4
- import { ICloudbaseRequest } from '@cloudbase/types/request';
5
- import { constants, adapters,utils, helpers } from '@cloudbase/utilities/';
6
- import { eventBus, EVENTS, LoginState } from '..';
7
- import { LOGINTYPE } from '../constants';
8
-
9
- const { getSdkName, ERRORS, COMMUNITY_SITE_URL } = constants;
10
- const { RUNTIME } = adapters;
11
- const { getQuery, getHash, removeParam, printWarn } = utils;
12
- const { catchErrorsDecorator } = helpers;
13
-
14
- export class WeixinAuthProvider extends AuthProvider {
15
- private readonly _scope: string;
16
- private readonly _state: string;
17
- private readonly _appid: string;
18
- private readonly _runtime:string;
19
-
20
- constructor(config: ICloudbaseAuthConfig&{cache:ICloudbaseCache,request:ICloudbaseRequest,runtime:string}, appid: string, scope: string, state?: string) {
21
- super(config);
22
-
23
- this._runtime = config.runtime;
24
- this._appid = appid;
25
- this._scope = scope;
26
- this._state = state || 'weixin';
27
- }
28
-
29
- public async signIn(){
30
- return printWarn(ERRORS.OPERATION_FAIL,'API signIn has been deprecated, please use signInWithRedirect insteed');
31
- }
32
- @catchErrorsDecorator({
33
- title: '跳转微信公众号授权失败',
34
- messages: [
35
- '请确认以下各项:',
36
- ' 1 - 调用 auth().weixinAuthProvider().signInWithRedirect() 的语法或参数是否正确',
37
- `如果问题依然存在,建议到官方问答社区提问或寻找帮助:${COMMUNITY_SITE_URL}`
38
- ]
39
- })
40
- public async signInWithRedirect() {
41
- return this._redirect();
42
- }
43
- @catchErrorsDecorator({
44
- title: '微信公众号登录失败',
45
- messages: [
46
- '请确认以下各项:',
47
- ' 1 - 调用 auth().weixinAuthProvider().getRedirectResult() 的语法或参数是否正确',
48
- ' 2 - 当前环境是否开通了微信公众号登录授权',
49
- ' 3 - 微信公众号的 AppId 与 AppSecret 配置是否正确',
50
- `如果问题依然存在,建议到官方问答社区提问或寻找帮助:${COMMUNITY_SITE_URL}`
51
- ]
52
- })
53
- public async getRedirectResult(options:{ withUnionId?: boolean; syncUserInfo?: boolean }) {
54
- const code = getWeixinCode();
55
- if (!code) {
56
- return null;
57
- }
58
- return this._signInWithCode(code,options);
59
- }
60
- @catchErrorsDecorator({
61
- title: '获取微信重定向绑定结果',
62
- messages: [
63
- '请确认以下各项:',
64
- ' 1 - 调用 auth().weixinAuthProvider().getLinkRedirectResult() 的语法或参数是否正确',
65
- ' 2 - 当前环境是否开通了微信公众号登录授权',
66
- ' 3 - 微信公众号的 AppId 与 AppSecret 配置是否正确',
67
- `如果问题依然存在,建议到官方问答社区提问或寻找帮助:${COMMUNITY_SITE_URL}`
68
- ]
69
- })
70
- async getLinkRedirectResult(options: { withUnionId?: boolean } = {}) {
71
- const { withUnionId = false } = options;
72
- const code = getWeixinCode();
73
- if (!code) {
74
- return null;
75
- }
76
- const { _appid: appid } = this;
77
- const loginType = (scope => {
78
- switch (scope) {
79
- case 'snsapi_login':
80
- return 'WECHAT-OPEN';
81
- default:
82
- return 'WECHAT-PUBLIC';
83
- }
84
- })(this._scope);
85
- const hybridMiniapp = this._runtime === RUNTIME.WX_MP ? '1' : '0';
86
- return this._request.send('auth.linkWithWeixinCode', {
87
- payload: {
88
- appid,
89
- loginType,
90
- code,
91
- hybridMiniapp,
92
- withUnionId
93
- }
94
- });
95
- }
96
-
97
- private _redirect(): any {
98
- let currUrl = removeParam('code', location.href);
99
- currUrl = removeParam('state', currUrl);
100
- currUrl = encodeURIComponent(currUrl);
101
-
102
- let host = '//open.weixin.qq.com/connect/oauth2/authorize';
103
- if (this._scope === 'snsapi_login') {
104
- host = '//open.weixin.qq.com/connect/qrconnect';
105
- }
106
- try{
107
- location.href = `${host}?appid=${this._appid}&redirect_uri=${currUrl}&response_type=code&scope=${this._scope}&state=${this._state}#wechat_redirect`;
108
- }catch(e){
109
- throw new Error(`[${getSdkName()}][${ERRORS.UNKOWN_ERROR}]${e}`)
110
- }
111
- }
112
-
113
- private async _signInWithCode(code:string,options) {
114
- const { accessTokenKey, accessTokenExpireKey, refreshTokenKey } = this._cache.keys;
115
- // 有code,用code换refresh token
116
- const loginType = (scope => {
117
- switch (scope) {
118
- case 'snsapi_login':
119
- return 'WECHAT-OPEN';
120
- default:
121
- return 'WECHAT-PUBLIC';
122
- }
123
- })(this._scope);
124
-
125
- const refreshTokenRes = await this._getRefreshTokenByWXCode(this._appid, loginType, code,options);
126
- const { refreshToken } = refreshTokenRes;
127
-
128
- // 本地存下
129
- await this._cache.setStoreAsync(refreshTokenKey, refreshToken);
130
- if (refreshTokenRes.accessToken) {
131
- await this._cache.setStoreAsync(accessTokenKey, refreshTokenRes.accessToken);
132
- }
133
- if (refreshTokenRes.accessTokenExpire) {
134
- await this._cache.setStoreAsync(accessTokenExpireKey, String(refreshTokenRes.accessTokenExpire + Date.now()));
135
- }
136
- eventBus.fire(EVENTS.LOGIN_STATE_CHANGED);
137
- // 抛出登录类型更改事件
138
- eventBus.fire(EVENTS.LOGIN_TYPE_CHANGED, {
139
- env: this._config.env,
140
- loginType: LOGINTYPE.WECHAT,
141
- persistence: this._config.persistence
142
- });
143
- await this.refreshUserInfo();
144
- const loginState = new LoginState({
145
- envId: this._config.env,
146
- cache: this._cache,
147
- request: this._request
148
- });
149
- await loginState.checkLocalStateAsync();
150
-
151
- return loginState;
152
- }
153
-
154
- private async _getRefreshTokenByWXCode(
155
- appid: string,
156
- loginType: string,
157
- code: string,
158
- options: any = {}
159
- ): Promise<{ refreshToken: string; accessToken: string; accessTokenExpire: number }> {
160
- const { withUnionId = false, createUser = true } = options;
161
- // snsapi_userinfo 和 snsapi_login 才可以获取用户的微信信息
162
- const syncUserInfo = this._scope === 'snsapi_base' ? false : options.syncUserInfo || false;
163
-
164
- const action = 'auth.signIn';
165
- const hybridMiniapp = this._runtime === RUNTIME.WX_MP ? '1' : '0';
166
- return this._request.send(action, {
167
- appid,
168
- loginType,
169
- hybridMiniapp,
170
- syncUserInfo,
171
- loginCredential: code,
172
- withUnionId,
173
- createUser
174
- }).then(res => {
175
- if (res.code) {
176
- throw new Error(`[${getSdkName()}][${ERRORS.OPERATION_FAIL}] failed login via wechat: ${res.code}`);
177
- }
178
- if (res.refresh_token) {
179
- return {
180
- refreshToken: res.refresh_token,
181
- accessToken: res.access_token,
182
- accessTokenExpire: res.access_token_expire
183
- };
184
- } else {
185
- throw new Error(`[${getSdkName()}][${ERRORS.OPERATION_FAIL}] action:getJwt not return refreshToken`);
186
- }
187
- });
188
- }
189
- }
190
-
191
- function getWeixinCode () {
192
- return getQuery('code') || getHash('code');
193
- };