Reputation: 81
I'm having an issue where my Django application (using social-auth-app-django 5.4.1) is creating URLs that are giving errors when integrated with Google's sign in.
The unwrapped text in this error is: Request details: redirect_uri=
http://127.0.0.1:8000/accounts/complete/google-oauth2/ flowName=GeneralOAuthFlow
There is a whitespace between google-oauth2/
and flowName
. Google does not allow whitespace in the names of their redirect URIs.
As far as I am aware, I am not in control of how this section of the URL is constructed, so I'm a bit of a loss as to how I am going to resolve this.
For context, this error is encountered after attempting to press the below link, wrapped in the social:begin link provided by social-auth-app-django:
<a href="{% url 'social:begin' 'google-oauth2' %}" class="btn bsb-btn-xl btn-outline-primary btn-form-orange-inv">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-google" viewBox="0 0 16 16">
<path d="M15.545 6.558a9.42 9.42 0 0 1 .139 1.626c0 2.434-.87 4.492-2.384 5.885h.002C11.978 15.292 10.158 16 8 16A8 8 0 1 1 8 0a7.689 7.689 0 0 1 5.352 2.082l-2.284 2.284A4.347 4.347 0 0 0 8 3.166c-2.087 0-3.86 1.408-4.492 3.304a4.792 4.792 0 0 0 0 3.063h.003c.635 1.893 2.405 3.301 4.492 3.301 1.078 0 2.004-.276 2.722-.764h-.003a3.702 3.702 0 0 0 1.599-2.431H8v-3.08h7.545z" />
</svg>
<span class="ms-2 fs-6">Google</span>
Related settings are as follows:
# Authentication Backends
AUTHENTICATION_BACKENDS = (
'social_core.backends.google.GoogleOAuth2',
'django.contrib.auth.backends.ModelBackend',
)
# Google OAuth2
SOCIAL_AUTH_GOOGLE_OAUTH2_KEY = config('GOOGLE_CLIENT_ID') + '.apps.googleusercontent.com'
SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET = config('GOOGLE_CLIENT_SECRET')
SOCIAL_AUTH_URL_NAMESPACE = 'social'
LOGIN_REDIRECT_URL = '/dashboard/'
LOGOUT_REDIRECT_URL = '/'
And main urls.py:
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('home.urls')),
path('', include('users.urls')),
path('dashboard/', include('dashboard.urls')),
path('accounts/', include('social_django.urls', namespace='social')),
]
Is it likely that the whitespace is an error with the package, or with my code? If the latter, how should I proceed in resolving this issue?
Upvotes: 1
Views: 270
Reputation: 81
It turns out, despite this whitespace, it did not matter.
http://127.0.0.1:8000/accounts/complete/google-oauth2/
This, obviously, is a valid URI for this purpose.
Upvotes: 0