Closed dsrizvi closed 9 years ago
Here are my settings:
""" Django settings for beerstash project.
Generated by 'django-admin startproject' using Django 1.8.4.
For more information on this file, see https://docs.djangoproject.com/en/1.8/topics/settings/
For the full list of settings and their values, see https://docs.djangoproject.com/en/1.8/ref/settings/ """
import os from config import *
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(file)))
SECRET_KEY =***
DEBUG = True
ALLOWED_HOSTS = []
INSTALLED_APPS = ( 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'rest_framework', 'oauth2_provider', 'users', 'social.apps.django_app.default', 'rest_framework_social_oauth2',
)
AUTHENTICATION_BACKENDS = (
# Facebook OAuth2
'social.backends.facebook.FacebookAppOAuth2',
'social.backends.facebook.FacebookOAuth2',
# django-rest-framework-social-oauth2
'rest_framework_social_oauth2.backends.DjangoOAuth2',
# Django
'django.contrib.auth.backends.ModelBackend',
)
SOCIAL_AUTH_PIPELINE = ( 'social.pipeline.social_auth.social_details', 'social.pipeline.social_auth.social_uid', 'social.pipeline.social_auth.auth_allowed', 'social.pipeline.social_auth.social_user', 'social.pipeline.user.get_username', 'social.pipeline.user.create_user', 'social.pipeline.social_auth.associate_user', 'social.pipeline.social_auth.load_extra_data', 'social.pipeline.user.user_details'
'users.pipeline.user_details'
)
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': (
# OAuth
'oauth2_provider.ext.rest_framework.OAuth2Authentication',
'rest_framework_social_oauth2.authentication.SocialAuthentication',
)
}
OAUTH2_PROVIDER = {
'SCOPES': {'read': 'Read scope', 'write': 'Write scope'}
}
MIDDLEWARE_CLASSES = ( 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.auth.middleware.SessionAuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', 'django.middleware.security.SecurityMiddleware', )
ROOT_URLCONF = 'blackbox_server.urls'
TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': ['templates'], 'APP_DIRS': True, 'OPTIONS': { 'context_processors': [ 'django.template.context_processors.debug', 'django.template.context_processors.request', 'django.contrib.auth.context_processors.auth', 'django.contrib.messages.context_processors.messages', 'social.apps.django_app.context_processors.backends', 'social.apps.django_app.context_processors.login_redirect',
],
},
},
]
WSGI_APPLICATION = 'blackbox_server.wsgi.application'
DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), } }
SOCIAL_AUTH_FACEBOOK_KEY = *** SOCIAL_AUTH_FACEBOOK_SECRET = ** SOCIAL_AUTH_FACEBOOK_SCOPE = [ 'email', 'user_friends', 'friends_location', ] SOCIAL_AUTH_STRATEGY = 'social.strategies.django_strategy.DjangoStrategy' SOCIAL_AUTH_STORAGE = 'social.apps.django_app.default.models.DjangoStorage'
SOCIAL_AUTH_LOGIN_REDIRECT_URL = '/' SOCIAL_AUTH_LOGIN_ERROR_URL = '/'
AUTH_PROFILE_MODULE = "users.UserProfile"
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
STATIC_URL = '/static/'
Here is my urls.py:
from django.conf.urls import patterns, include, url from django.contrib import admin
urlpatterns = patterns( '',
url(r'^$', 'dashboard.views.login'),
# # url(r'^home/$', 'dashboard.views.home'),
# # url(r'^logout/$', 'dashboard.views.logout'),
# # authentication
url('', include('social.apps.django_app.urls', namespace='social')),
url(r'^o/', include('oauth2_provider.urls', namespace='oauth2_provider')),
# my apps
url(r'^admin/', include(admin.site.urls)),
url(r'^users/', include('users.urls')),
)
Nevermind, figured it out.
what happend ? same problem here..
same here.
bendspax : add this lines to your url.py file:
url(r'^social/', include('social.apps.django_app.urls', namespace='social')),
url(r'^auth/', include('rest_framework_social_oauth2.urls')),
This should solve the problem :)
bendspax : add this lines to your url.py file:
url(r'^social/', include('social.apps.django_app.urls', namespace='social')), url(r'^auth/', include('rest_framework_social_oauth2.urls')),
This should solve the problem :)
Also, just adding on to this, make sure you have added this in settings.py file
AUTHENTICATION_BACKENDS = (
# Others auth providers (e.g. Google, OpenId, etc)
# Facebook OAuth2
'social_core.backends.facebook.FacebookAppOAuth2',
'social_core.backends.facebook.FacebookOAuth2',
# django-rest-framework-social-oauth2
'rest_framework_social_oauth2.backends.DjangoOAuth2',
# Django
'django.contrib.auth.backends.ModelBackend',
)
In the settings.py, add this line at the end:
DRFSO2_URL_NAMESPACE = "drfso2"
Have a legitimate issue this time. When I go to the django admin site, I get this error
`Environment:
Request Method: POST Request URL: http://localhost:8000/admin/login/?next=/admin/
Django Version: 1.8.4 Python Version: 2.7.8 Installed Applications: ('django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'rest_framework', 'oauth2_provider', 'users', 'social.apps.django_app.default', 'rest_framework_social_oauth2') Installed Middleware: ('django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.auth.middleware.SessionAuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', 'django.middleware.security.SecurityMiddleware')
Traceback: File "/Users/danyalrizvi/Google_Drive/Work/gigster/blackbox/blackbox-virtualenv/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
Exception Type: NoReverseMatch at /admin/login/ Exception Value: Reverse for 'authorize' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []'
From my understanding the offending line is
AUTHORIZATION_URL = reverse('authorize')
called byclass DjangoOAuth2(BaseOAuth2):
. I don't understand why the rest_framework_social_oauth2 is involved at all with the default django admin.