1

我正在尝试使用带有自定义 axios 响应拦截器的vue-authenticate的 oauth2 提供程序进行身份验证,如下所示:

  bindRequestInterceptor() {
    this.$http.interceptors.request.use((config) => {
      console.log('Axios intercetping request')
      console.log(`Before checking Token : ${this.getToken()}`)
      if (this.isAuthenticated()) {
        console.log('Authenticated')
        config.headers.Authorization = [
          this.options.tokenType, this.getToken(),
        ].join(' ')
      } else {
        console.log('Not authenticated')
        delete config.headers.Authorization
        let this_ = this;
        this.authenticate('oauth2').then(function(authResponse){
          console.log(authResponse)
          this_.isAuthenticated = this_.$auth.isAuthenticated();

        })//This fires an oauth popup window
      }
      console.log(`After checking Token : ${this.getToken()}`)
      return config
    })
  },

运行 ajax 调用时: - 我在窗口中被重定向到我的授权 url ( /oauth/authorize) - 批准后,我成功地使用授权代码重定向到我的自定义。redirect_uri

我的问题是,为什么我不能authenticated在这个流程之后。事实上,如果我通过 axios 重新调用 ajax,它会从授权流程(批准窗口等)中重新循环我

这里有没有人熟悉这个工具,以及如何解决这个问题?

注意:当关闭审批窗口时,我在调用 ajax 的页面中收到此错误

Possible Unhandled Promise Rejection: Error: Auth popup window closed

注2:根据上述代码的控制台日志

Axios intercetping request
app.js?id=01021d92b5ff42f0b696:30471 Before checking Token : null
app.js?id=01021d92b5ff42f0b696:30479 Not authenticated
app.js?id=01021d92b5ff42f0b696:30487 After checking Token : null
4

0 回答 0