If you really want to use 'Javascript-only to connect to Github, or any other OAuth provider that does not support OAuth2 'implicit' grant type/flow, and you do not mind using an OAuth-based web service, which greatly simplifies everything to a < 10 lines, you can try to use OAuth.io (https://oauth.io).
OAuth.io provides an open-source Javascript library: https://cdn.rawgit.com/oauth-io/oauth-js/c5af4519/dist/oauth.js. The library communicates with the OAuth.io server, which is configured with your Github (OAuth server) client id/client secret, so it acts as a intermediary between your browser, and Github (or any OAuth provider), making it capable of completing the OAuth2 'authorization code' grant type/flow.
The code then is as simple as:
OAuth.popup('github').then(github => {
console.log('github:', github);
// You can use the github object to
// perform any HTTP get/post to Github API endpoints
github.get('/user').then(data => {
console.log('self data:', data);
})
});
Reference: https://coderwall.com/p/sjbwcq/javascript-github-social-login-button-for-oauth
username
andpassword
in header of that request.