Browse Source

[bug-371] token失效自动更新时报错

cfort 2 years ago
parent
commit
32ff7284d9
1 changed files with 4 additions and 1 deletions
  1. 4 1
      src/api/oauth2/oauth2.js

+ 4 - 1
src/api/oauth2/oauth2.js

@@ -215,6 +215,8 @@ OAuth.prototype.getAuthorizeURLForWebsite = function (redirect, state, scope) {
  * @param {Function} callback 回调函数
  */
 OAuth.prototype.getAccessTokenByCode = function (code, callback) {
+    // 存储用户名,用于刷新token传参
+    localStorage.setItem('username', this.username)
     const args = {
         url: OAUTH2_URL() + '/authentication/apply',
         data: {
@@ -300,13 +302,14 @@ OAuth.prototype.getAccessTokenByPassword = function ({ username, password }, cal
  * @param {Function} callback 回调函数
  */
 OAuth.prototype.refreshAccessToken = function (refreshToken, callback) {
+    const username = localStorage.getItem('username')
     const args = {
         url: OAUTH2_URL() + '/authentication/apply',
         data: {
             client_id: this.clientId,
             client_secret: this.clientSecret,
             grant_type: 'refresh_token',
-            username: this.username,
+            username,
             refresh_token: refreshToken
         },
         method: 'post'