admin管理员组文章数量:1279016
I'm using a Javascript to do Basic Authentication with GitHub. For example, the following shell mand gets a token from Github:
curl -i -u uaername:password -k -d "{\"scopes\": [\"repo\"]}"
How do you achieve that with jQuery and AJAX?
I'm using a Javascript to do Basic Authentication with GitHub. For example, the following shell mand gets a token from Github:
curl -i -u uaername:password -k -d "{\"scopes\": [\"repo\"]}" https://api.github./authorizations
How do you achieve that with jQuery and AJAX?
Share Improve this question edited May 21, 2018 at 19:49 Carl Younger 3,08025 silver badges38 bronze badges asked Aug 8, 2013 at 11:17 Nick PapamanolioudakisNick Papamanolioudakis 791 silver badge4 bronze badges 02 Answers
Reset to default 7Including 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.
Are you asking whether there is a way to get an oAuth token purely from the client side? If so, the answer is no.
But, you have some work arounds.
Github.js: https://github./michael/github
Gatekeeper is an open source server side ponent which can help with oAuth tokens management:
https://github./prose/gatekeeper
You could also use something like Firebase with simple login and in this case you don't need to manage any server side services:
https://www.firebase./docs/security/simple-login-github.html
本文标签: javascriptClientside GitHub AuthenticationStack Overflow
版权声明:本文标题:javascript - Clientside GitHub Authentication - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741254645a2366434.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论