gh-valid

1.1.0 • Public • Published

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

Readme

Keywords

none

Package Sidebar

Install

npm i gh-valid

Weekly Downloads

1

Version

1.1.0

License

MIT

Unpacked Size

6.71 kB

Total Files

4

Last publish

Collaborators

  • sidoshi