Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to add custom authorisation headers? #415

Open
clembou opened this issue Jan 15, 2017 · 3 comments
Open

Add ability to add custom authorisation headers? #415

clembou opened this issue Jan 15, 2017 · 3 comments

Comments

@clembou
Copy link

clembou commented Jan 15, 2017

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 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 #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
      if (this.__customHeaders) {
         headers = Object.assign(headers, this.__customHeaders);
      }

in __getRequestHeaders__

  • make sure __customHeaders gets passed to the various subclasses constructors across the library

I noticed that a new AcceptHeader parameter was recently added, perhaps this could be consolidated with my proposed change (e.g. you could just passe {Accept: 'v3'} as custom headers.

@clayreimann
Copy link
Member

This seems like a good addition to me. That way as the Github API evolves it will be easy to add whatever new headers we need

@afc163
Copy link

afc163 commented Apr 29, 2017

Note: The topics property for repositories on GitHub is currently available for developers to preview. To view the topics property in calls that return repository results, you must provide a custom media type in the Accept header:

application/vnd.github.mercy-preview+json

Seems that we do need a custom header for topics field now.

@danwenzel
Copy link

I recommend switching to https://github.com/octokit/rest.js. It's better-maintained, and can do what you're looking for

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants