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

Github Enterprise has a different API endpoint compared to Free/Pro/teams version #1309

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions docs/auth.rst
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ Here's an example configuration file with the Github OAuth options:
Replace `<your_client_id>` and `<your_client_secret>` with the actual Client ID and secret obtained from
the Github Settings.

If using Github Enterprise, you can set the `FLOWER_GITHUB_OAUTH_DOMAIN` environment variable to the base URL of your Github Enterprise instance.

See `GitHub OAuth API`_ docs for more info.

.. _Github Settings: https://github.com/settings/applications/new
Expand Down
6 changes: 5 additions & 1 deletion flower/views/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ class GithubLoginHandler(BaseHandler, tornado.auth.OAuth2Mixin):

_OAUTH_DOMAIN = os.getenv(
"FLOWER_GITHUB_OAUTH_DOMAIN", "github.com")
if _OAUTH_DOMAIN == "github.com":
_OAUTH_API_URL = f'https://api.{_OAUTH_DOMAIN}/user/emails'
else:
_OAUTH_API_URL = f'https://{_OAUTH_DOMAIN}/api/v3/user/emails'
_OAUTH_AUTHORIZE_URL = f'https://{_OAUTH_DOMAIN}/login/oauth/authorize'
_OAUTH_ACCESS_TOKEN_URL = f'https://{_OAUTH_DOMAIN}/login/oauth/access_token'
_OAUTH_NO_CALLBACKS = False
Expand Down Expand Up @@ -138,7 +142,7 @@ async def _on_auth(self, user):
access_token = user['access_token']

response = await self.get_auth_http_client().fetch(
f'https://api.{self._OAUTH_DOMAIN}/user/emails',
self._OAUTH_API_URL,
headers={'Authorization': 'token ' + access_token,
'User-agent': 'Tornado auth'})

Expand Down
Loading