New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

github-oauth-express

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github-oauth-express

A small package to enable Github Login and access to your Express application

latest
Source
npmnpm
Version
1.0.4
Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

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

Keywords

github

FAQs

Package last updated on 20 Dec 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts