🚀 Big News:Socket Has Acquired Secure Annex.Learn More →
Socket
Book a DemoSign in
Socket

gh-valid

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gh-valid

Check if a GitHub token is valid and has the right scopes

latest
Source
npmnpm
Version
1.1.0
Version published
Maintainers
1
Created
Source

gh-valid

Build Status contributions welcome HitCount npm npm

Check if a GitHub token is valid and has the right scopes

Install

npm install --save gh-valid

Usage

import ghValid from 'gh-valid'

// A github token with notification and repo scope
const token = process.env.GITHUB_TOKEN

// Check if the token is valid
ghValid(token).then(({ tokenValid, scopesValid, scopes }) => {
  console.log(tokenValid) // true
  console.log(scopesValid) // true
  console.log(scopes) // ['notifications', 'repo']
})

// Check if a token is valid and has required scopes
ghValid(token, ['notification', 'gists']).then(
  ({ tokenValid, scopesValid, scopes }) => {
    console.log(tokenValid) // true
    console.log(scopesValid) // false, Since gists scope is not available
    console.log(scopes) // ['notifications', 'repo']
  }
)

// When token is invalid
ghValid('invalid_token').then(({ tokenValid, scopesValid, scopes }) => {
  console.log(tokenValid) // false
  console.log(scopesValid) // false
  console.log(scopes) // []
})

License

MIT © Siddharth Doshi

FAQs

Package last updated on 10 May 2018

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