[英]failed to obtain access token from angular script
我正在尝试获取一些访问令牌以使用远程应用程序中托管的一些其他api,当我从curl代理和某些插件(如Open HttpRequester)发送请求时,我成功获取了这些令牌,并且我成功使用了其他api。
但是,当我尝试从角度脚本功能请求令牌时,我收到了401未经授权的消息。
我想在角度js post方法中等效于这个curl请求。
curl -X POST -vu clientapp:123456 http://localhost:8080/oauth/token -H "Accept: application/json" -d "password=spring&username=roy&grant_type=password&scope=read%20write&client_secret=123456&client_id=clientapp".
我不知道在post angular方法中如何包括clientapp:123456对。
这是脚本
var app = angular.module("app", []);
app.controller("MyController", function($scope, $http) {
$scope.obtain_token = function() {
$http({
method : 'POST',
url : 'http://clientapp:123456@localhost:8080/oauth/token',
data: {
username:'roy',
password: 'spring',
client_id: 'clientapp',
client_secret: '123456',
scope: 'write'
},
transformRequest: function(obj) {
var str = [];
for (var p in obj)
str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
return str.join("&");
}}).success(function (data, status, headers, config){
alert(data.access_token);
}).error(function (data, status, headers, config){
//alert("Errooooooooor");
});
};
});
我尝试了您的版本,但无法正常工作。
您可以发布到网址:
http://clientapp:123456@localhost:8080/oauth/token
如果使用HTTP身份验证。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.