From 441a8b52308279a4131e40c83bcbfe32f225a5bf Mon Sep 17 00:00:00 2001 From: Clovin Date: Fri, 2 Dec 2022 13:11:27 +0800 Subject: [PATCH] fix lint issue --- backend/config/settings/base.py | 11 ++++------- backend/config/urls.py | 4 ++-- backend/pyproject.toml | 6 ++++-- backend/social/okta.py | 2 +- backend/social/urls.py | 2 +- backend/social/v1_urls.py | 2 +- backend/social/views.py | 30 +++++++++++++++++------------- 7 files changed, 30 insertions(+), 27 deletions(-) diff --git a/backend/config/settings/base.py b/backend/config/settings/base.py index a052d6e4..bc9d2ffb 100644 --- a/backend/config/settings/base.py +++ b/backend/config/settings/base.py @@ -283,12 +283,9 @@ CELERY_RESULT_SERIALIZER = "json" DEFAULT_AUTO_FIELD = "django.db.models.AutoField" SOCIALACCOUNT_PROVIDERS = { - 'okta': { - 'OKTA_BASE_URL': env("OAUTH_OKTA_OAUTH2_API_URL", ''), - 'OAUTH_PKCE_ENABLED': True, - 'APP': { - 'client_id': env("OAUTH_OKTA_OAUTH2_KEY", ''), - 'secret': env("OAUTH_OKTA_OAUTH2_SECRET", '') - } + "okta": { + "OKTA_BASE_URL": env("OAUTH_OKTA_OAUTH2_API_URL", ""), + "OAUTH_PKCE_ENABLED": True, + "APP": {"client_id": env("OAUTH_OKTA_OAUTH2_KEY", ""), "secret": env("OAUTH_OKTA_OAUTH2_SECRET", "")}, } } diff --git a/backend/config/urls.py b/backend/config/urls.py index 2cb5130a..9c633091 100644 --- a/backend/config/urls.py +++ b/backend/config/urls.py @@ -52,8 +52,8 @@ if settings.DEBUG or os.environ.get("STANDALONE", False): urlpatterns += [ path("admin/", admin.site.urls), path("api-auth/", include("rest_framework.urls")), - path('social/', include("social.urls")), - path('v1/social/', include("social.v1_urls")), + path("social/", include("social.urls")), + path("v1/social/", include("social.v1_urls")), path("v1/health/", include("health_check.urls")), path("v1/", include("api.urls")), path("v1/", include("roles.urls")), diff --git a/backend/pyproject.toml b/backend/pyproject.toml index 6b4c4221..0992395d 100644 --- a/backend/pyproject.toml +++ b/backend/pyproject.toml @@ -125,7 +125,8 @@ known_first_party = [ "metrics", "projects", "roles", - "users" + "users", + "social" ] known_local_folder = [ "api", @@ -139,7 +140,8 @@ known_local_folder = [ "metrics", "projects", "roles", - "users" + "users", + "social" ] [tool.taskipy.tasks] diff --git a/backend/social/okta.py b/backend/social/okta.py index 7568a2c7..3f85b34f 100644 --- a/backend/social/okta.py +++ b/backend/social/okta.py @@ -5,5 +5,5 @@ from dj_rest_auth.registration.views import SocialLoginView class OktaLogin(SocialLoginView): adapter_class = OktaOAuth2Adapter - callback_url = '/projects' + callback_url = "/projects" client_class = OAuth2Client diff --git a/backend/social/urls.py b/backend/social/urls.py index c5d091f2..faa53f59 100644 --- a/backend/social/urls.py +++ b/backend/social/urls.py @@ -3,5 +3,5 @@ from django.urls import path from .okta import OktaLogin urlpatterns = [ - path('complete/okta-oauth2/', OktaLogin.as_view(), name='okta_login'), + path("complete/okta-oauth2/", OktaLogin.as_view(), name="okta_login"), ] diff --git a/backend/social/v1_urls.py b/backend/social/v1_urls.py index 5a6a5e5a..61cba70c 100644 --- a/backend/social/v1_urls.py +++ b/backend/social/v1_urls.py @@ -3,5 +3,5 @@ from django.urls import path from .views import Social urlpatterns = [ - path('links/', Social.as_view()), + path("links/", Social.as_view()), ] diff --git a/backend/social/views.py b/backend/social/views.py index 3c2549dc..8a8942e3 100644 --- a/backend/social/views.py +++ b/backend/social/views.py @@ -7,16 +7,20 @@ class Social(APIView): permission_classes = () def get(self, request, *args, **kwargs): - return Response({ - 'okta': { - 'type': 'oauth2', - 'base_url': settings.SOCIALACCOUNT_PROVIDERS.get('okta').get('OKTA_BASE_URL'), - 'client_id': settings.SOCIALACCOUNT_PROVIDERS.get('okta').get('APP').get('client_id'), - 'redirect_path': '/social/complete/okta-oauth2', - 'authorize_url': - 'https://' + settings.SOCIALACCOUNT_PROVIDERS.get('okta').get('OKTA_BASE_URL') - + '/oauth2/v1/authorize?response_type=code&client_id=' - + settings.SOCIALACCOUNT_PROVIDERS.get('okta').get('APP').get('client_id') - + '&scope=openid&state=unknown&response_mode=form_post', - } if settings.SOCIALACCOUNT_PROVIDERS.get('okta').get('OKTA_BASE_URL') else {}, - }) + return Response( + { + "okta": { + "type": "oauth2", + "base_url": settings.SOCIALACCOUNT_PROVIDERS.get("okta").get("OKTA_BASE_URL"), + "client_id": settings.SOCIALACCOUNT_PROVIDERS.get("okta").get("APP").get("client_id"), + "redirect_path": "/social/complete/okta-oauth2", + "authorize_url": "https://" + + settings.SOCIALACCOUNT_PROVIDERS.get("okta").get("OKTA_BASE_URL") + + "/oauth2/v1/authorize?response_type=code&client_id=" + + settings.SOCIALACCOUNT_PROVIDERS.get("okta").get("APP").get("client_id") + + "&scope=openid&state=unknown&response_mode=form_post", + } + if settings.SOCIALACCOUNT_PROVIDERS.get("okta").get("OKTA_BASE_URL") + else {}, + } + )