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

added Authorization header if access_token provided #954

Merged
merged 2 commits into from
Sep 20, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions binderhub/repoproviders.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,13 +435,13 @@ def _access_token_default(self):
auth = Dict(
help="""Auth parameters for the GitHub API access

Populated from client_id, client_secret, access_token.
Populated from client_id, client_secret.
"""
)
@default('auth')
def _default_auth(self):
auth = {}
for key in ('client_id', 'client_secret', 'access_token'):
for key in ('client_id', 'client_secret'):
value = getattr(self, key)
if value:
auth[key] = value
Expand Down Expand Up @@ -477,6 +477,10 @@ def github_api_request(self, api_url, etag=None):
api_url = url_concat(api_url, self.auth)

headers = {}
# based on: https://developer.github.com/v3/#oauth2-token-sent-in-a-header
if self.access_token:
headers['Authorization'] = "token {token}".format(token=self.access_token)

if etag:
headers['If-None-Match'] = etag
req = HTTPRequest(api_url, headers=headers, user_agent="BinderHub")
Expand Down