加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angularjs – 如何在Header Angular JS中传递授权令牌

发布时间:2020-12-17 17:10:04 所属栏目:安全 来源:网络整理
导读:在我的控制器中,我试图调用我的API,但我无法传递Autherization令牌. 我创建了一个config var并在其中传递我的令牌,但获得了以下响应: 900902Missing Credentials需要未提供的OAuth凭据.确保您的API调用调用有一个标题:“授权:Bearer ACCESS_TOKEN” ** JS
在我的控制器中,我试图调用我的API,但我无法传递Autherization令牌.

我创建了一个config var并在其中传递我的令牌,但获得了以下响应:

900902Missing Credentials需要未提供的OAuth凭据.确保您的API调用调用有一个标题:“授权:Bearer ACCESS_TOKEN”

** JS代码**

app.controller("AuthenticationController",function($scope,API_URL,vcRecaptchaService,$http) {

       var config = {
         headers: {
           'Authorization': 'Bearer 00000-e5673-346756f-8676-f7567561a'
         }
       };
       $scope.verifyRecaptcha = function() {

         if (vcRecaptchaService.getResponse() === "") {
           alert("User did not resolve the recaptcha")
         } else {
           var post_data = {
             'g-recaptcha-response': vcRecaptchaService.getResponse()
           }
           $http.post('https:1.1.1.1/abc/vdc/verify',config,post_data).success(function(response) {

               if (response.success === true) {
                 alert("Successfully resolved the recaptcha.");
               } else {
                 alert("User verification failed");
               }
             })
             .error(function(error) {
               alert("Error Occured while resolving recaptcha.");
               console.log(error);
             })
         }
       }

解决方法

我想你已经改变了有效载荷和标题的位置

应该
http.post(url,data,config)而不是http.post(url,data)

链接到doc

如果我可以给你一个建议,我会将所有逻辑放在一个http拦截器中,因此auth头将附加到每个请求.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读