Skip to content
This repository was archived by the owner on Aug 30, 2023. It is now read-only.
Closed
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
7 changes: 7 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,10 @@ Finally, obtain the API keys and plug them into your ``sentry.conf.py``:

GOOGLE_CLIENT_SECRET = ""

Alternatively, you can plug them into your ``config.yml``:

.. code-block:: python

auth-google.client-id: ""

auth-google.client-secret: ""
17 changes: 15 additions & 2 deletions sentry_auth_google/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,27 @@

from django.conf import settings

from sentry.options import (
FLAG_ALLOW_EMPTY,
FLAG_PRIORITIZE_DISK,
register)


AUTHORIZE_URL = 'https://accounts.google.com/o/oauth2/auth'

ACCESS_TOKEN_URL = 'https://www.googleapis.com/oauth2/v4/token'

CLIENT_ID = getattr(settings, 'GOOGLE_CLIENT_ID', None)

CLIENT_SECRET = getattr(settings, 'GOOGLE_CLIENT_SECRET', None)
register(
'auth-google.client-id',
default=getattr(settings, 'GOOGLE_CLIENT_ID', None),
flags=FLAG_ALLOW_EMPTY | FLAG_PRIORITIZE_DISK,
)
register(
'auth-google.client-secret',
default=getattr(settings, 'GOOGLE_CLIENT_SECRET', None),
flags=FLAG_ALLOW_EMPTY | FLAG_PRIORITIZE_DISK,
)

ERR_INVALID_DOMAIN = 'The domain for your Google account (%s) is not allowed to authenticate with this provider.'

Expand Down
11 changes: 6 additions & 5 deletions sentry_auth_google/provider.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
from __future__ import absolute_import, print_function

from sentry.options import get

from sentry.auth.providers.oauth2 import (
OAuth2Callback, OAuth2Provider, OAuth2Login
)

from .constants import (
AUTHORIZE_URL, ACCESS_TOKEN_URL, CLIENT_ID, CLIENT_SECRET, DATA_VERSION,
SCOPE
AUTHORIZE_URL, ACCESS_TOKEN_URL, DATA_VERSION, SCOPE
)
from .views import FetchUser, GoogleConfigureView


class GoogleOAuth2Login(OAuth2Login):
authorize_url = AUTHORIZE_URL
client_id = CLIENT_ID
client_id = get('auth-google.client-id')
scope = SCOPE

def __init__(self, domains=None):
Expand All @@ -34,8 +35,8 @@ def get_authorize_params(self, state, redirect_uri):

class GoogleOAuth2Provider(OAuth2Provider):
name = 'Google'
client_id = CLIENT_ID
client_secret = CLIENT_SECRET
client_id = get('auth-google.client-id')
client_secret = get('auth-google.client-secret')

def __init__(self, domain=None, domains=None, version=None, **config):
if domain:
Expand Down