From 6f5a10e491f329e084c6c22d11623fb093b5eec6 Mon Sep 17 00:00:00 2001 From: joaopna Date: Wed, 21 Aug 2024 17:40:59 -0300 Subject: [PATCH 1/2] changes to Django 3.0+, python 3.9+ and PEP --- oidc_auth/auth.py | 6 +++--- oidc_auth/models.py | 4 ++-- oidc_auth/urls.py | 6 +++--- oidc_auth/views.py | 7 ++++--- requirements.txt | 6 +++--- 5 files changed, 15 insertions(+), 14 deletions(-) diff --git a/oidc_auth/auth.py b/oidc_auth/auth.py index f81865c..f7c9020 100644 --- a/oidc_auth/auth.py +++ b/oidc_auth/auth.py @@ -24,9 +24,9 @@ def authenticate(self, **kwargs): id_token = provider.verify_id_token(credentials['id_token']) oidc_user = OpenIDUser.get_or_create(id_token, - credentials['access_token'], - credentials.get('refresh_token', ''), - provider) + credentials['access_token'], + credentials.get('refresh_token', ''), + provider) return oidc_user.user except Exception as e: diff --git a/oidc_auth/models.py b/oidc_auth/models.py index 97d0270..a4780f0 100644 --- a/oidc_auth/models.py +++ b/oidc_auth/models.py @@ -31,7 +31,7 @@ def generate(cls, redirect_url, issuer, length=oidc_settings.NONCE_LENGTH): """This method generates and returns a nonce, an unique generated string. If the maximum of retries is exceeded, it returns None. """ - CHARS = string.letters + string.digits + CHARS = string.ascii_letters + string.digits for i in range(5): _hash = ''.join(random.choice(CHARS) for n in range(length)) @@ -147,7 +147,7 @@ def verify_id_token(self, token): id_token = JWS().verify_compact(token, self.signing_keys) log.debug('Token verified, %s' % id_token) - return json.loads(id_token) + return id_token @staticmethod def _get_issuer(token): diff --git a/oidc_auth/urls.py b/oidc_auth/urls.py index 3bd2755..88d165d 100644 --- a/oidc_auth/urls.py +++ b/oidc_auth/urls.py @@ -1,8 +1,8 @@ from django.urls import path -from . import views +from oidc_auth import views urlpatterns = [ - path(r'^login/$', views.login_begin, name='oidc-login'), - path(r'^complete/$', views.login_complete, name='oidc-complete'), + path('login/', views.login_begin, name='oidc-login'), + path('complete/', views.login_complete, name='oidc-complete'), ] diff --git a/oidc_auth/views.py b/oidc_auth/views.py index 0013a75..b29fbc1 100644 --- a/oidc_auth/views.py +++ b/oidc_auth/views.py @@ -1,13 +1,14 @@ from urllib.parse import urlencode from django.conf import settings from django.http import HttpResponseBadRequest -from django.contrib.auth import REDIRECT_FIELD_NAME, authenticate, login as django_login +from django.contrib.auth import REDIRECT_FIELD_NAME, login as django_login from django.urls import reverse from django.shortcuts import render, redirect import requests from . import errors from . import utils +from .auth import OpenIDConnectBackend from .utils import log from .settings import oidc_settings from .forms import OpenIDConnectForm @@ -91,8 +92,8 @@ def login_complete(request, login_complete_view='oidc-complete', log.debug('Token exchange done, proceeding authentication') credentials = response.json() credentials['provider'] = provider - user = authenticate(credentials=credentials) - django_login(request, user) + user = OpenIDConnectBackend().authenticate(credentials=credentials) + django_login(request, user, backend='oidc_auth.auth.OpenIDConnectBackend') return redirect(nonce.redirect_url) diff --git a/requirements.txt b/requirements.txt index 2b64734..afea931 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,7 @@ # Production requirements -Django>1.9 -pyjwkest==0.6.2 -requests==2.2.1 +Django>=3.0 +pyjwkest>=1.1.5 +requests>=2.22.0 South==1.0.2 # Test requirements From e25303333dd41ebc9af72da12935b8fc1d599e60 Mon Sep 17 00:00:00 2001 From: joaopna Date: Wed, 21 Aug 2024 17:41:09 -0300 Subject: [PATCH 2/2] version update --- setup.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/setup.py b/setup.py index acf0add..4ce1ea8 100644 --- a/setup.py +++ b/setup.py @@ -4,17 +4,19 @@ setup( name='django-oidc-auth', - version='2.0.0', + version='3.0.0', description='OpenID Connect client for Django applications', long_description='WIP', - author='Lucas S. Magalhães, Daniel Pimentel', - author_email='lucas.sampaio@intelie.com.br, danielpimentel@lccv.ufal.br', + author='Lucas S. Magalhães, Daniel Pimentel, João Paulo de Araújo, Romero Malaquias', + author_email='lucas.sampaio@intelie.com.br, danielpimentel@lccv.ufal.br, joaopna@lccv.ufal.br, ' + 'romero.malaquias@edge.ufal.br', packages=find_packages(exclude=['*.tests']), include_package_data=True, install_requires=[ - 'Django>=4.2.8', - 'pyjwkest==1.4.2', - 'requests==2.31.0', + 'Django>=3.0', + 'South>=1.0.2', + 'pyjwkest>=1.1.5', + 'requests>=2.22.0', ], zip_safe=True )