1.0.4 • Published 4 years ago

github-oauth-express v1.0.4

Weekly downloads
17
License
ISC
Repository
github
Last release
4 years ago

github-oauth-express

  • A simple package to get the access_token of a Github account for a particular client. So that we can call Github's user specific APIs.
  • Follow these steps to create a Github App and get client_id, client_secret.
    • Login Github.
    • Click your profile icon -> Settings -> Developer Settings -> OAuth Apps -> New OAuth App.
    • Enter your app details and specifically callback URL.
  • In your App's Github Login button the redirection link must be
`https://github.com/login/oauth/authorize?client_id=${YOUR_CLIENT_ID}`;

npm.io

Implementation

Here you can obtain authToken using both callback way as well as promise way.

Promise

const express = require('express');
const app = express();

const githubAPI = require('github-oauth-express');

// YOUR EXPRESS APPLICATION

githubAPI(
  app, // Send your app instance to get OAuth Access
  {
    clientId: 'YOUR_CLIENT_ID',
    clientSecret: 'YOUR_CLIENT_SECRET',
    redirectURL: '/oauth-call'
  }
)
  .then(authToken => {
    console.log('authToken:', authToken);
  })
  .catch(err => console.log(err));

Callback

const express = require('express');
const app = express();

const githubAPI = require('github-oauth-express');

// YOUR EXPRESS APPLICATION

githubAPI(
  app, // Send your app instance to get OAuth Access
  {
    clientId: 'YOUR_CLIENT_ID',
    clientSecret: 'YOUR_CLIENT_SECRET',
    redirectURL: '/oauth-call'
  },
  (err, authToken) => {
    if (err) {
      console.log('err:', err);
      return;
    }

    console.log('authToken:', authToken);
  }
);

Once Auth Token obtained you can call Githubs Developer APIs by just adding a header in each request as

{
  "headers": {
    "Accept": "application/json"
  }
}
1.0.4

4 years ago

1.0.2

4 years ago

1.0.3

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago