2 years ago

#69093

test-img

user17953070

Django Rest Auth using google authentication

url.py

urlpatterns = [
    path('admin/', admin.site.urls),
    path('auth/', include('rest_auth.urls')),
    path('', GoogleLogin.as_view()),
    path('auth/google/callback/', google_callback, name='google_callback'),
    path('auth/google/url/', google_views.oauth2_login)
]

views.py

import urllib.parse
from allauth.socialaccount.providers.google import views as google_views
from allauth.socialaccount.providers.oauth2.client import OAuth2Client
from django.contrib import admin
from django.shortcuts import redirect
from django.urls import include, path, reverse
from rest_auth.registration.views import SocialLoginView


class GoogleLogin(SocialLoginView):
    adapter_class = google_views.GoogleOAuth2Adapter
    client_class = OAuth2Client

    @property
    def callback_url(self):
        return self.request.build_absolute_uri(reverse('google_callback'))


def google_callback(request):
    params = urllib.parse.urlencode(request.GET)
    return redirect(f' http://127.0.0.1:8000/auth/google/callback/')

Client ID for Web application

URIs :http://127.0.0.1:8000 Authorised redirect URIs : http://127.0.0.1:8000/auth/google/callback/

error: Authorization Error Error 400: redirect_uri_mismatch

You can't sign in to this app because it doesn't comply with Google's OAuth 2.0 policy.

If you're the app developer, register the redirect URI in the Google Cloud Console. Learn more The content in this section has been provided by the app developer. This content has not been reviewed or verified by Google. If you’re the app developer, make sure that these request details comply with Google policies.

redirect_uri: http://localhost:8000/auth/google/callback/

Pl help me. Thank you in advance. django-rest-auth using google authentication any reference documentation pl share me.

django

django-rest-framework

google-oauth

django-rest-auth

0 Answers

Your Answer

Accepted video resources