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

Update to django v2 #19

Merged
merged 3 commits into from
Jan 9, 2019
Merged
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
3 changes: 3 additions & 0 deletions 01-Login/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.env
db.sqlite3
*.pyc
16 changes: 8 additions & 8 deletions 01-Login/auth0login/auth0backend.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from six.moves.urllib import request
from urllib import request
from jose import jwt
from social_core.backends.oauth import BaseOAuth2

Expand All @@ -13,22 +13,22 @@ class Auth0(BaseOAuth2):
]

def authorization_url(self):
return "https://" + self.setting('DOMAIN') + "/authorize"
return 'https://' + self.setting('DOMAIN') + '/authorize'

def access_token_url(self):
return "https://" + self.setting('DOMAIN') + "/oauth/token"
return 'https://' + self.setting('DOMAIN') + '/oauth/token'

def get_user_id(self, details, response):
"""Return current user id."""
return details['user_id']

def get_user_details(self, response):
# Obtain JWT and the keys to validate the signature
idToken = response.get('id_token')
jwks = request.urlopen("https://" + self.setting('DOMAIN') + "/.well-known/jwks.json")
issuer = "https://" + self.setting('DOMAIN') + "/"
audience = self.setting('KEY') #CLIENT_ID
payload = jwt.decode(idToken, jwks.read(), algorithms=['RS256'], audience=audience, issuer=issuer)
id_token = response.get('id_token')
jwks = request.urlopen('https://' + self.setting('DOMAIN') + '/.well-known/jwks.json')
issuer = 'https://' + self.setting('DOMAIN') + '/'
audience = self.setting('KEY') # CLIENT_ID
payload = jwt.decode(id_token, jwks.read(), algorithms=['RS256'], audience=audience, issuer=issuer)

return {'username': payload['nickname'],
'first_name': payload['name'],
Expand Down
12 changes: 6 additions & 6 deletions 01-Login/auth0login/urls.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from django.conf.urls import url, include
from django.urls import path, include
from . import views

urlpatterns = [
url('^$', views.index),
url(r'^dashboard', views.dashboard),
url(r'^', include('django.contrib.auth.urls', namespace='auth')),
url(r'^', include('social_django.urls', namespace='social')),
]
path('', views.index),
path('dashboard/', views.dashboard),
path('', include('django.contrib.auth.urls')),
path('', include('social_django.urls')),
]
2 changes: 1 addition & 1 deletion 01-Login/auth0login/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def index(request):
@login_required
def dashboard(request):
user = request.user
auth0user = user.social_auth.get(provider="auth0")
auth0user = user.social_auth.get(provider='auth0')
userdata = {
'user_id': auth0user.uid,
'name': user.first_name,
Expand Down
9 changes: 4 additions & 5 deletions 01-Login/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
django<=1.11
social-auth-app-django
python-jose
six
python-dotenv
django~=2.1
social-auth-app-django~=3.1
python-jose~=3.0
python-dotenv~=0.9
8 changes: 4 additions & 4 deletions 01-Login/webappexample/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@
if ENV_FILE:
load_dotenv(ENV_FILE)

# SOCIAL AUTH AUTH0 BACKEND CONFIG
# SOCIAL AUTH AUTH0 BACKEND CONFIG
SOCIAL_AUTH_TRAILING_SLASH = False
SOCIAL_AUTH_AUTH0_KEY = os.environ.get('AUTH0_CLIENT_ID')
SOCIAL_AUTH_AUTH0_SECRET = os.environ.get('AUTH0_CLIENT_SECRET')
Expand All @@ -150,6 +150,6 @@
}


LOGIN_URL = "/login/auth0"
LOGIN_REDIRECT_URL = "/dashboard"
LOGOUT_REDIRECT_URL = "/"
LOGIN_URL = '/login/auth0'
LOGIN_REDIRECT_URL = '/dashboard'
LOGOUT_REDIRECT_URL = '/'
6 changes: 3 additions & 3 deletions 01-Login/webappexample/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
1. Import the include() function: from django.conf.urls import url, include
2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls'))
"""
from django.conf.urls import url, include
from django.urls import path, include
from django.contrib import admin

urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^', include('auth0login.urls'))
path('admin/', admin.site.urls),
path('', include('auth0login.urls'))
]