我试图在angularjs中发出请求来检索访问令牌,但我不是100%确定如何去做。下面是卷曲在angularjs中发出OAuth2请求
卷曲-X POST请求-d “grant_type =密码&用户名= &密码= &范围=读” -u “:” http://localhost:8000/o/token/
任何和所有帮助认识
我试图在angularjs中发出请求来检索访问令牌,但我不是100%确定如何去做。下面是卷曲在angularjs中发出OAuth2请求
卷曲-X POST请求-d “grant_type =密码&用户名= &密码= &范围=读” -u “:” http://localhost:8000/o/token/
任何和所有帮助认识
我认为你需要发布与查询字符串参数
要做到这一点,你需要ŧ Ø在您的POST请求一些修改
var request = $http({
method: "POST",
url: "",
transformRequest: transformRequestAsFormPost,
data: {
grant_type: "password",
username: "Kim",
password: "123",
scope: "read"
}
});
下面是详细信息https://www.bennadel.com/blog/2615-posting-form-data-with-http-in-angularjs.htm
我想通了
var data = "grant_type=password" + "&username="+cred.username + "&password="+cred.password +
"&client_id=" + cred.client_id +
"&client_secret=" + cred.client_secret;
$http({
method: 'POST',
url: 'BaseUrl',
data: data,
headers: {'Content-Type': 'application/x-www-form-urlencoded'}
})
解释