如何使用angularjs进行基本身份验证?
在github中,有一个部分可以进行基本的身份验证。。。如果我使用的是curl,这看起来像:如何使用angularjs进行基本身份验证?,angularjs,authentication,github-api,Angularjs,Authentication,Github Api,在github中,有一个部分可以进行基本的身份验证。。。如果我使用的是curl,这看起来像: $ curl -u <username>:<token> https://api.github.com/user $curl-u:https://api.github.com/user 如果我要在angular中执行此操作,如何将其转换为http请求?我最终设法解决了此问题。我的答案是根据我的经验得出的 这就是方法!我对你使用的令牌很好奇,它是JWT吗?你把它存放在哪里?我一
$ curl -u <username>:<token> https://api.github.com/user
$curl-u:https://api.github.com/user
如果我要在angular中执行此操作,如何将其转换为http请求?我最终设法解决了此问题。我的答案是根据我的经验得出的
这就是方法!我对你使用的令牌很好奇,它是JWT吗?你把它存放在哪里?我一直想在前端安全方面提供帮助:)如果您正在构建前端应用程序,您可能会发现我的博客文章很有用:
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. }
}
);
}