Self hosted FLOSS fitness/workout, nutrition and weight tracker
Feat: Implement dj-rest-auth for Google OAuth API endpoints
pankaj-basnet10e26e40d298
diff --git a/pyproject.toml b/pyproject.tomlindex 92a3570c9..5a266bfa0 100644--- a/pyproject.toml+++ b/pyproject.toml@@ -49,6 +49,7 @@ dependencies = ["djangorestframework-simplejwt[crypto,python_jose]~=5.5.1","djangorestframework~=3.17.1","django~=6.0.5",+ "dj-rest-auth~=7.2.0","drf-spectacular[sidecar]~=0.29.0","easy-thumbnails~=2.10.1","flower~=2.0.1",diff --git a/settings/settings_global.py b/settings/settings_global.pyindex 1e207d7a6..b4c34fccd 100644--- a/settings/settings_global.py+++ b/settings/settings_global.py@@ -127,6 +127,10 @@ INSTALLED_APPS = ['allauth.mfa','allauth.socialaccount','allauth.socialaccount.providers.google',++ # Dj-rest-auth+ 'dj_rest_auth',+ 'dj_rest_auth.registration',]MIDDLEWARE = [@@ -500,6 +504,11 @@ SIMPLE_JWT = {'UPDATE_LAST_LOGIN': False,}+#+# Dj-rest-auth+#+REST_USE_JWT = True+## CORS headers: allow all hosts to access the API#diff --git a/wger/core/api/views.py b/wger/core/api/views.pyindex 0fc15a509..0cc4190e7 100644--- a/wger/core/api/views.py+++ b/wger/core/api/views.py@@ -55,6 +55,9 @@ from rest_framework.permissions import (IsAuthenticated,)from rest_framework.response import Response+from allauth.socialaccount.providers.google.views import GoogleOAuth2Adapter+from allauth.socialaccount.providers.oauth2.client import OAuth2Client+from dj_rest_auth.registration.views import SocialLoginView# wger# The per-app powersync modules are imported for their side effect: each one@@ -371,6 +374,13 @@ class UserAPIRegistrationViewSet(viewsets.ViewSet):status=status.HTTP_201_CREATED,)+class GoogleLogin(SocialLoginView):+ """+ REST endpoint to exchange a Google Access Token for a wger API JWT.+ """+ adapter_class = GoogleOAuth2Adapter+ client_class = OAuth2Client+ callback_url = "http://127.0.0.1:8000/accounts/google/login/callback/"class LanguageViewSet(viewsets.ReadOnlyModelViewSet):"""diff --git a/wger/urls.py b/wger/urls.pyindex 6ab8dc046..e0b5f01a6 100644--- a/wger/urls.py+++ b/wger/urls.py@@ -374,6 +374,9 @@ urlpatterns += [name='api-redoc',),path('accounts/', include('allauth.urls')),+ path('auth/', include('dj_rest_auth.urls')),+ path('auth/registration/', include('dj_rest_auth.registration.urls')),+ path('auth/google/', core_api_views.GoogleLogin.as_view(), name='google_rest_login'),]#