Node Promiscuous Modules

    github-oauth-express

    1.0.4 • Public • Published

    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}`;

    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"
      }
    }

    Install

    npm i github-oauth-express

    DownloadsWeekly Downloads

    2

    Version

    1.0.4

    License

    ISC

    Unpacked Size

    5.99 kB

    Total Files

    4

    Last publish

    Collaborators

    • sivanesh_s