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