gh-valid
v1.1.0
Published
Check if a GitHub token is valid and has the right scopes
Downloads
3
Readme
gh-valid
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