Skip to content

sidoshi/gh-valid

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

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

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published