Created
July 15, 2012 20:24
-
-
Save ghickman/3118490 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
AUTHENTICATION_BACKENDS = ( | |
'social_auth.backends.google.GoogleOAuth2Backend', | |
'django.contrib.auth.backends.ModelBackend', | |
) | |
LOGIN_REDIRECT_URL = '/' | |
GOOGLE_OAUTH2_CLIENT_ID = os.environ['GOOGLE_OAUTH2_CLIENT_ID'] | |
GOOGLE_OAUTH2_CLIENT_SECRET = os.environ['GOOGLE_OAUTH2_CLIENT_SECRET'] | |
GOOGLE_WHITE_LISTED_DOMAINS = ['incuna.com'] | |
SOCIAL_AUTH_USER_MODEL = 'auth.User' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.conf.urls import * | |
from django.contrib import admin | |
from .views import AuthComplete, LoginError | |
admin.autodiscover() | |
urlpatterns = patterns('', | |
# some other urls | |
url(r'^admin/', include(admin.site.urls)), | |
url(r'^complete/(?P<backend>[^/]+)/$', AuthComplete.as_view()), | |
url(r'^login-error/$', LoginError.as_view()), | |
url(r'', include('social_auth.urls')), | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.core.urlresolvers import reverse | |
from django.contrib import messages | |
from django.http import HttpResponse, HttpResponseRedirect | |
from django.views.generic.base import View | |
from social_auth.backends.exceptions import AuthFailed | |
from social_auth.views import complete | |
class AuthComplete(View): | |
def get(self, request, *args, **kwargs): | |
backend = kwargs.pop('backend') | |
try: | |
return complete(request, backend, *args, **kwargs) | |
except AuthFailed: | |
messages.error(request, "Your Google Apps domain isn't authorized for this app") | |
return HttpResponseRedirect(reverse('login')) | |
class LoginError(View): | |
def get(self, request, *args, **kwargs): | |
return HttpResponse(status=401) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment