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 0
Add a ment  | 

2 Answers 2

Reset to default 7

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.

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