gh-got
Advanced tools
Comparing version 8.0.0 to 8.0.1
@@ -17,3 +17,3 @@ 'use strict'; | ||
if (options.token) { | ||
options.headers.authorization = `token ${options.token}`; | ||
options.headers.authorization = options.headers.authorization || `token ${options.token}`; | ||
} | ||
@@ -20,0 +20,0 @@ |
{ | ||
"name": "gh-got", | ||
"version": "8.0.0", | ||
"version": "8.0.1", | ||
"description": "Convenience wrapper for `got` to interact with the GitHub API", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -92,4 +92,31 @@ # gh-got [![Build Status](https://travis-ci.org/sindresorhus/gh-got.svg?branch=master)](https://travis-ci.org/sindresorhus/gh-got) | ||
## Authorization | ||
Authorization for GitHub uses the following logic: | ||
1. If `options.headers.authorization` is passed to `gh-got`, then this will be used as first preference. | ||
2. If `options.token` is provided, then the `authorization` header will be set to `token <options.token>`. | ||
3. If `options.headers.authorization` and `options.token` are not provided, then the `authorization` header will be set to `token <process.env.GITHUB_TOKEN>` | ||
In most cases, this means you can simply set `GITHUB_TOKEN`, but it also allows it to be overridden by setting `options.token` or `options.headers.authorization` explicitly. For example, if [authenticating as a GitHub App](https://developer.github.com/apps/building-github-apps/authenticating-with-github-apps/#authenticating-as-a-github-app), you could do the following: | ||
```js | ||
const ghGot = require(`gh-got`); | ||
(async () => { | ||
const options = { | ||
headers: { | ||
authorization: `Bearer ${jwt}` | ||
} | ||
}; | ||
const {body} = await ghGot('app', options); | ||
console.log(body.name); | ||
//=> 'MyApp' | ||
})(); | ||
``` | ||
## License | ||
MIT © [Sindre Sorhus](https://sindresorhus.com) |
5732
122