1.1.0 • Published 6 years ago

gh-valid v1.1.0

Weekly downloads
2
License
MIT
Repository
github
Last release
6 years ago

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