github-tools / github-tools/github

Add ability to add custom authorisation headers?

Aperta
#415 3 commenti 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
JavaScript
Stelle
3.8k
Fork
809
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

I am working on an app where I would like to use github.js to access an internal api acting as a proxy to `api.github.com`.

I am doing this because I want to expose specific github features to non github members (the ability to log issues in private repositories for example).

the internal api simply forwards the api calls to `api.github.com` using a pre-configured token that has the appropriate scopes.

Unfortunately github uses `token` as a keyword in the token authorisation header, but my api uses the more standard `bearer` keyword. I did a [trivial fix](https://github.com/clembou/github/commit/16a434127ab6d73e172fb662c61283274be41d3a) in my fork that lets me change this. However I would like to avoid using a fork of the library if at all possible.

Would you accept a PR adding support for passing additional headers that would allow users to add or override default values? This would be a more generic way to fix my issue and might be of interest to other users (it is mentionned in https://github.com/github-tools/github/issues/322 for example).

if so I am happy to take a stab at it.

I would probably do the following:
- add a `__customHeaders` property initialised from a new optional parameter on `Requestable`
- add something like
```js
if (this.__customHeaders) {
headers = Object.assign(headers, this.__customHeaders);
}
```
in [`__getRequestHeaders__`](https://github.com/clembou/github/blob/master/lib/Requestable.js#L105)
- make sure __customHeaders gets passed to the various subclasses constructors across the library

I noticed that a new [`AcceptHeader`](https://github.com/github-tools/github/blob/master/lib/Requestable.js#L49) parameter was recently added, perhaps this could be consolidated with my proposed change (e.g. you could just passe `{Accept: 'v3'}` as custom headers.

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Direzione di ricerca

Inizia in lib/Requestable.js, in __getRequestHeaders__ e nel costruttore di Requestable, poi esamina i vari costruttori delle sottoclassi per vedere come verrebbe propagata la nuova opzione. Confronta gli header personalizzati proposti con il parametro AcceptHeader esistente; il lavoro è completato quando i chiamanti possono fornire o sovrascrivere gli header di autorizzazione senza usare un fork.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
javascript
Ambito
api
Tipo di issue
Funzionalità
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.