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); }) } } 解决方法
我想你已经改变了有效载荷和标题的位置
应该 链接到doc 如果我可以给你一个建议,我会将所有逻辑放在一个http拦截器中,因此auth头将附加到每个请求. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |