客户端GitHub身份验证 [英] Clientside GitHub Authentication
本文介绍了客户端GitHub身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用Javascript对GitHub进行基本身份验证.例如,以下shell命令从Github获取令牌:
curl -i -u uaername:password -k -d "{\"scopes\": [\"repo\"]}" https://api.github.com/authorizations
如何使用jQuery和AJAX实现这一目标?
解决方案
在jQuery的HTTP标头中包含基本Auth数据
您可以使用Authorization
字段在标题中包含基本身份验证详细信息.您已经了解jQuery的工作原理.此代码段包含您所缺少的部分:
let auth = btoa(username + ":" + password);
jQuery.ajax({
url: ...,
headers: { Authorization: "Basic " + auth }
...
});
注意:btoa
和atob
(读作 B到A 和 A到B )是内置函数,可以与 MDN文档. >
I'm using a Javascript to do Basic Authentication with GitHub. For example, the following shell command gets a token from Github:
curl -i -u uaername:password -k -d "{\"scopes\": [\"repo\"]}" https://api.github.com/authorizations
How do you achieve that with jQuery and AJAX?
解决方案
Including Basic Auth Data in HTTP Headers with jQuery
You can include basic auth details in the header using the Authorization
field. You already understand how jQuery works. This snippet has the bits you're missing:
let auth = btoa(username + ":" + password);
jQuery.ajax({
url: ...,
headers: { Authorization: "Basic " + auth }
...
});
Note: btoa
and atob
(pronounced B to A and A to B) are builtin functions, and convert to and from Base64. See the MDN docs for more information.
这篇关于客户端GitHub身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文