1
在github上,有这个部分,你可以做基本身份验证...如果我用卷曲,这看起来像:如何使用angularjs进行基本身份验证?
$ curl -u <username>:<token> https://api.github.com/user
我如何把它转换成HTTP请求,如果我是这样做的角?
在github上,有这个部分,你可以做基本身份验证...如果我用卷曲,这看起来像:如何使用angularjs进行基本身份验证?
$ curl -u <username>:<token> https://api.github.com/user
我如何把它转换成HTTP请求,如果我是这样做的角?
我终于设法解决了它。我根据我的回答从icodeya。
function authenticateUser(username, authtoken) {
var url = "https://api.github.com/user"
var credentials = btoa(username + ':' + authtoken);
var authorization = {'Authorization': 'Basic ' + credentials};
var header = { headers: authorization }
return $http.get(url, header)
.then(function(response) {
function() { //do something here. }
}
);
}
就是这么做的!我很好奇你使用的令牌,它是一个智威汤逊?你在哪里存储它?我总是希望帮助前端安全:)如果您正在构建前端应用程序,您可能会发现我的博客文章很有用: [单页面应用程序的基于令牌的身份验证](https:// stormpath.com/blog/build-secure-user-interfaces-using-jwts/) [https://stormpath.com/blog/build-secure-user-interfaces-using-jwts/](https:// stormpath.com/blog/token-auth-spa/) – robertjd