https://github.com/sidoshi/gh-valid
Check if a GitHub token is valid and has the right scopes
https://github.com/sidoshi/gh-valid
Last synced: 3 months ago
JSON representation
Check if a GitHub token is valid and has the right scopes
- Host: GitHub
- URL: https://github.com/sidoshi/gh-valid
- Owner: sidoshi
- License: mit
- Created: 2018-05-10T19:28:01.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-05-10T19:29:00.000Z (over 7 years ago)
- Last Synced: 2025-04-01T14:21:13.893Z (9 months ago)
- Language: JavaScript
- Size: 59.6 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# gh-valid
[](https://travis-ci.org/sidoshi/gh-valid) [](https://github.com/sidoshi/gh-valid/issues) [](http://hits.dwyl.io/sidoshi/gh-valid) [](https://www.npmjs.com/package/gh-valid) [](https://www.npmjs.com/package/gh-valid)
> Check if a GitHub token is valid and has the right scopes
## Install
```bash
npm install --save gh-valid
```
## Usage
```js
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](https://sid.sh)