【问题标题】:API call with JWT token and an ID in URL使用 JWT 令牌和 URL 中的 ID 调用 API
【发布时间】:2021-10-10 01:13:13
【问题描述】:

我正在开发一个 Angular 应用程序,其中一个请求被发送到 express 后端。通过请求,我使用 auth-interceptor 在标头中附加了一个 JWT 令牌。 API请求地址如下:

http://localhost:3000/api/:userID/askQuestion

我正在从前端发送 URL 中的 userId 和标头中的 JWT 令牌。

但是当我发送任何请求时,后端没有授权路由。 注意:我在后端使用标头中的 JWT 令牌授权路由。 因此,当我发送请求时,auth-interceptor 没有设置 auth-token包含 URL 参数的路由标头。

它工作得很好 不包含任何 URL 参数的路由

【问题讨论】:

    标签: angularjs express jwt http-headers url-parameters


    【解决方案1】:

    您可以尝试使用 config 方法为每个请求添加自定义标头。

     angular.module('myApp', [])
     .config(function($httpProvider) {
        $httpProvider.defaults.headers
        .common['X-Requested-Url-Header'] = 'http://localhost:3000/api/:userID/askQuestion';
     });
    

    【讨论】:

      猜你喜欢
      • 2018-09-13
      • 2018-08-19
      • 2020-08-28
      • 2021-08-12
      • 1970-01-01
      • 2020-12-26
      • 1970-01-01
      • 2019-11-07
      相关资源
      最近更新 更多