Clientside GitHub Authentication
github-api, javascript
Solution
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.
Problem
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?