# social (Google) OAuth 2.0 authentication

**URL:** <https://forum.djangoproject.com/t/social-google-oauth-2-0-authentication/20574>\
**Category:** Mystery Errors\
**Created:** [April 27, 2023, 2:44pm UTC](https://forum.djangoproject.com/t/social-google-oauth-2-0-authentication/20574 "2023-04-27T14:44:23Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![coder1](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/coder1/32/13466_2.png) [@coder1](https://forum.djangoproject.com/u/coder1)\
**Post date:** [April 27, 2023, 2:44pm UTC](https://forum.djangoproject.com/t/social-google-oauth-2-0-authentication/20574/1 "2023-04-27T14:44:23Z")

</div>

Currently developing a django app, and I used social (Google) OAuth 2.0 authentication.

I deleted the app from my local computer and git cloned it. Google Sign-in was working fine, I deleted the app for something else.

Anyways, after I cloned it from github, when when I tried “sign in with google”, it says “`Exception Value: Reverse for 'google_login' not found. 'google_login' is not a valid view function or pattern name.`”, it’s also highlighting `<a href="{% provider_login_url 'google'%}?next=/">`.

I don’t think that I need to I define the url, because I installed django-allauth, and it should come with that. I am just so confused why would it work before and after I git cloned it, it stop working. Couldn’t find out the reason online.

Any idea? Thanks!

---

<div class="post-metadata">

**Author:** ![CodenameTim](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/codenametim/32/31507_2.png) [@CodenameTim](https://forum.djangoproject.com/u/CodenameTim)\
**Post date:** [April 27, 2023, 8:05pm UTC](https://forum.djangoproject.com/t/social-google-oauth-2-0-authentication/20574/2 "2023-04-27T20:05:14Z")

</div>

The [setup steps include creating some data in the admin](https://django-allauth.readthedocs.io/en/latest/providers.html#django-configuration). Did you redo that step as well?

---

<div class="post-metadata">

**Author:** ![coder1](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/coder1/32/13466_2.png) [@coder1](https://forum.djangoproject.com/u/coder1)\
**Post date:** [April 27, 2023, 8:49pm UTC](https://forum.djangoproject.com/t/social-google-oauth-2-0-authentication/20574/4 "2023-04-27T20:49:07Z")

</div>

Yup. The info was still in there under social applications.

---

<div class="post-metadata">

**Author:** ![CodenameTim](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/codenametim/32/31507_2.png) [@CodenameTim](https://forum.djangoproject.com/u/CodenameTim)\
**Post date:** [April 27, 2023, 8:53pm UTC](https://forum.djangoproject.com/t/social-google-oauth-2-0-authentication/20574/5 "2023-04-27T20:53:02Z")

</div>

Can you install `django-extensions` and run `python manage.py show_urls`, then copy/paste the output here? I’m not super familiar with allauth, but I think the urls should get registered in there.

---

<div class="post-metadata">

**Author:** ![CodenameTim](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/codenametim/32/31507_2.png) [@CodenameTim](https://forum.djangoproject.com/u/CodenameTim)\
**Post date:** [April 27, 2023, 8:56pm UTC](https://forum.djangoproject.com/t/social-google-oauth-2-0-authentication/20574/6 "2023-04-27T20:56:24Z")

</div>

Can you share your `INSTALLED_APPS` setting too please?

---

<div class="post-metadata">

**Author:** ![coder1](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/coder1/32/13466_2.png) [@coder1](https://forum.djangoproject.com/u/coder1)\
**Post date:** [April 27, 2023, 9:10pm UTC](https://forum.djangoproject.com/t/social-google-oauth-2-0-authentication/20574/7 "2023-04-27T21:10:09Z")

</div>

Yes.

```auto
**settings.py**
INSTALLED_APPS = [
    'main_app',
    'widget_tweaks',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.sites',
    'allauth',
    'allauth.account',
    'allauth.socialaccount',
    'allauth.socialaccount.providers.google',
]

SOCIALACCOUNT_LOGIN_ON_GET=True

AUTHENTICATION_BACKENDS = [
    'allauth.account.auth_backends.AuthenticationBackend'
]
SOCIALACCOUNT_PROVIDERS = {
    'google': {
        'SCOPE': [
            'profile',
            'email',
        ],
        'AUTH_PARAMS': {
            'access_type': 'online',
        }
    }
}

STATIC_URL = 'static/'
LOGIN_REDIRECT_URL = '/'
LOGOUT_REDIRECT_URL = '/'

**url.py**
urlpatterns = [
    path('admin/', admin.site.urls),
    path('accounts/', include('django.contrib.auth.urls')),
    path('social/signup/', views.signup_redirect, name='signup_redirect'), 
    path('', include('allauth.urls')),
    path('', include('main_app.urls')),
]

```

---

<div class="post-metadata">

**Author:** ![coder1](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/coder1/32/13466_2.png) [@coder1](https://forum.djangoproject.com/u/coder1)\
**Post date:** [April 27, 2023, 9:23pm UTC](https://forum.djangoproject.com/t/social-google-oauth-2-0-authentication/20574/8 "2023-04-27T21:23:14Z")

</div>

Sorry, I missed this message earlier.

```auto
/ main_app.views.home home
/accounts/login/ django.contrib.auth.views.LoginView login
/accounts/logout/ django.contrib.auth.views.LogoutView logout
/accounts/password_change/ django.contrib.auth.views.PasswordChangeView password_change
/accounts/password_change/done/ django.contrib.auth.views.PasswordChangeDoneView password_change_done
/accounts/password_reset/ django.contrib.auth.views.PasswordResetView password_reset
/accounts/password_reset/done/ django.contrib.auth.views.PasswordResetDoneView password_reset_done
/accounts/reset/<uidb64>/<token>/ django.contrib.auth.views.PasswordResetConfirmView password_reset_confirm
/accounts/reset/done/ django.contrib.auth.views.PasswordResetCompleteView password_reset_complete
/accounts/signup/ main_app.views.signup signup
/admin/ django.contrib.admin.sites.index admin:index
/admin/<app_label>/ django.contrib.admin.sites.app_index admin:app_list
/admin/<url> django.contrib.admin.sites.catch_all_view
/admin/account/emailaddress/ django.contrib.admin.options.changelist_view admin:account_emailaddress_changelist
/admin/account/emailaddress/<path:object_id>/ django.views.generic.base.RedirectView
/admin/account/emailaddress/<path:object_id>/change/ django.contrib.admin.options.change_view admin:account_emailaddress_change
/admin/account/emailaddress/<path:object_id>/delete/ django.contrib.admin.options.delete_view admin:account_emailaddress_delete
/admin/account/emailaddress/<path:object_id>/history/ django.contrib.admin.options.history_view admin:account_emailaddress_history
/admin/account/emailaddress/add/ django.contrib.admin.options.add_view admin:account_emailaddress_add
/admin/auth/group/ django.contrib.admin.options.changelist_view admin:auth_group_changelist
/admin/auth/group/<path:object_id>/ django.views.generic.base.RedirectView
/admin/auth/group/<path:object_id>/change/ django.contrib.admin.options.change_view admin:auth_group_change
/admin/auth/group/<path:object_id>/delete/ django.contrib.admin.options.delete_view admin:auth_group_delete
/admin/auth/group/<path:object_id>/history/ django.contrib.admin.options.history_view admin:auth_group_history
/admin/auth/group/add/ django.contrib.admin.options.add_view admin:auth_group_add
/admin/auth/user/ django.contrib.admin.options.changelist_view admin:auth_user_changelist
/admin/auth/user/<id>/password/ django.contrib.auth.admin.user_change_password admin:auth_user_password_change
/admin/auth/user/<path:object_id>/ django.views.generic.base.RedirectView
/admin/auth/user/<path:object_id>/change/ django.contrib.admin.options.change_view admin:auth_user_change
/admin/auth/user/<path:object_id>/delete/ django.contrib.admin.options.delete_view admin:auth_user_delete
/admin/auth/user/<path:object_id>/history/ django.contrib.admin.options.history_view admin:auth_user_history
/admin/auth/user/add/ django.contrib.auth.admin.add_view admin:auth_user_add
/admin/autocomplete/ django.contrib.admin.sites.autocomplete_view admin:autocomplete
/admin/jsi18n/ django.contrib.admin.sites.i18n_javascript admin:jsi18n
/admin/login/ django.contrib.admin.sites.login admin:login
/admin/logout/ django.contrib.admin.sites.logout admin:logout
/admin/main_app/photo/ django.contrib.admin.options.changelist_view admin:main_app_photo_changelist
/admin/main_app/photo/<path:object_id>/ django.views.generic.base.RedirectView
/admin/main_app/photo/<path:object_id>/change/ django.contrib.admin.options.change_view admin:main_app_photo_change
/admin/main_app/photo/<path:object_id>/delete/ django.contrib.admin.options.delete_view admin:main_app_photo_delete
/admin/main_app/photo/<path:object_id>/history/ django.contrib.admin.options.history_view admin:main_app_photo_history
/admin/main_app/photo/add/ django.contrib.admin.options.add_view admin:main_app_photo_add
/admin/main_app/post/ django.contrib.admin.options.changelist_view admin:main_app_post_changelist
/admin/main_app/post/<path:object_id>/ django.views.generic.base.RedirectView
/admin/main_app/post/<path:object_id>/change/ django.contrib.admin.options.change_view admin:main_app_post_change
/admin/main_app/post/<path:object_id>/delete/ django.contrib.admin.options.delete_view admin:main_app_post_delete
/admin/main_app/post/<path:object_id>/history/ django.contrib.admin.options.history_view admin:main_app_post_history
/admin/main_app/post/add/ django.contrib.admin.options.add_view admin:main_app_post_add
/admin/password_change/ django.contrib.admin.sites.password_change admin:password_change
/admin/password_change/done/ django.contrib.admin.sites.password_change_done admin:password_change_done
/admin/r/<int:content_type_id>/<path:object_id>/ django.contrib.contenttypes.views.shortcut admin:view_on_site
/admin/sites/site/ django.contrib.admin.options.changelist_view admin:sites_site_changelist
/admin/sites/site/<path:object_id>/ django.views.generic.base.RedirectView
/admin/sites/site/<path:object_id>/change/ django.contrib.admin.options.change_view admin:sites_site_change
/admin/sites/site/<path:object_id>/delete/ django.contrib.admin.options.delete_view admin:sites_site_delete
/admin/sites/site/<path:object_id>/history/ django.contrib.admin.options.history_view admin:sites_site_history
/admin/sites/site/add/ django.contrib.admin.options.add_view admin:sites_site_add
/admin/socialaccount/socialaccount/ django.contrib.admin.options.changelist_view admin:socialaccount_socialaccount_changelist
/admin/socialaccount/socialaccount/<path:object_id>/ django.views.generic.base.RedirectView
/admin/socialaccount/socialaccount/<path:object_id>/change/ django.contrib.admin.options.change_view admin:socialaccount_socialaccount_change
/admin/socialaccount/socialaccount/<path:object_id>/delete/ django.contrib.admin.options.delete_view admin:socialaccount_socialaccount_delete
/admin/socialaccount/socialaccount/<path:object_id>/history/ django.contrib.admin.options.history_view admin:socialaccount_socialaccount_history
/admin/socialaccount/socialaccount/add/ django.contrib.admin.options.add_view admin:socialaccount_socialaccount_add
/admin/socialaccount/socialapp/ django.contrib.admin.options.changelist_view admin:socialaccount_socialapp_changelist
/admin/socialaccount/socialapp/<path:object_id>/ django.views.generic.base.RedirectView
/admin/socialaccount/socialapp/<path:object_id>/change/ django.contrib.admin.options.change_view admin:socialaccount_socialapp_change
/admin/socialaccount/socialapp/<path:object_id>/delete/ django.contrib.admin.options.delete_view admin:socialaccount_socialapp_delete
/admin/socialaccount/socialapp/<path:object_id>/history/ django.contrib.admin.options.history_view admin:socialaccount_socialapp_history
/admin/socialaccount/socialapp/add/ django.contrib.admin.options.add_view admin:socialaccount_socialapp_add
/admin/socialaccount/socialtoken/ django.contrib.admin.options.changelist_view admin:socialaccount_socialtoken_changelist
/admin/socialaccount/socialtoken/<path:object_id>/ django.views.generic.base.RedirectView
/admin/socialaccount/socialtoken/<path:object_id>/change/ django.contrib.admin.options.change_view admin:socialaccount_socialtoken_change
/admin/socialaccount/socialtoken/<path:object_id>/delete/ django.contrib.admin.options.delete_view admin:socialaccount_socialtoken_delete
/admin/socialaccount/socialtoken/<path:object_id>/history/ django.contrib.admin.options.history_view admin:socialaccount_socialtoken_history
/admin/socialaccount/socialtoken/add/ django.contrib.admin.options.add_view admin:socialaccount_socialtoken_add
/chatter/ main_app.views.posts_index posts_index
/chatter/<int:pk>/delete/ main_app.views.PostDelete post_delete
/chatter/<int:pk>/edit/ main_app.views.PostEdit post_edit
/chatter/<int:post_id>/ main_app.views.post_detail post_detail
/chatter/<int:post_id>/add_photo main_app.views.add_photo add_photo
/chatter/<int:post_id>/delete_photo/<int:photo_id>/ main_app.views.delete_photo delete_photo
/chatter/compose/ main_app.views.PostCompose post_compose
/confirm-email/ allauth.account.views.EmailVerificationSentView account_email_verification_sent
/confirm-email/<key>/ allauth.account.views.ConfirmEmailView account_confirm_email
/email/ allauth.account.views.EmailView account_email
/inactive/ allauth.account.views.AccountInactiveView account_inactive
/login/ allauth.account.views.LoginView account_login
/logout/ allauth.account.views.LogoutView account_logout
/password/change/ allauth.account.views.PasswordChangeView account_change_password
/password/reset/ allauth.account.views.PasswordResetView account_reset_password
/password/reset/done/ allauth.account.views.PasswordResetDoneView account_reset_password_done
/password/reset/key/<uidb36>-<key>/ allauth.account.views.PasswordResetFromKeyView account_reset_password_from_key
/password/reset/key/done/ allauth.account.views.PasswordResetFromKeyDoneView account_reset_password_from_key_done
/password/set/ allauth.account.views.PasswordSetView account_set_password
/search/ main_app.views.search search
/signup/ allauth.account.views.SignupView account_signup
/social/connections/ allauth.socialaccount.views.ConnectionsView socialaccount_connections
/social/login/cancelled/ allauth.socialaccount.views.LoginCancelledView socialaccount_login_cancelled
/social/login/error/ allauth.socialaccount.views.LoginErrorView socialaccount_login_error
/social/signup/ allauth.socialaccount.views.SignupView socialaccount_signup
/social/signup/ main_app.views.signup_redirect signup_redirect

```

Thank you so much for your help.

---

<div class="post-metadata">

**Author:** ![CodenameTim](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/codenametim/32/31507_2.png) [@CodenameTim](https://forum.djangoproject.com/u/CodenameTim)\
**Post date:** [April 27, 2023, 10:22pm UTC](https://forum.djangoproject.com/t/social-google-oauth-2-0-authentication/20574/10 "2023-04-27T22:22:33Z")

</div>

Odd. So I added allauth to a project of mine and installed it with the INSTALLED\_APPS and to the urlpatterns how you did, and I get the following URL patterns:

```auto
/google/login/	allauth.socialaccount.providers.oauth2.views.view	google_login
/google/login/callback/	allauth.socialaccount.providers.oauth2.views.view	google_callback

```

It’s likely that `'allauth.socialaccount.providers.google',` isn’t being registered as an `INSTALLED_APPS` element. Check that you’re using the correct settings file and/or what the values are. Or if anything manipulates it.

You could also try verifying what version of allauth you have installed and compare to what the latest version of allauth.

---

<div class="post-metadata">

**Author:** ![coder1](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/coder1/32/13466_2.png) [@coder1](https://forum.djangoproject.com/u/coder1)\
**Post date:** [April 28, 2023, 1:00am UTC](https://forum.djangoproject.com/t/social-google-oauth-2-0-authentication/20574/11 "2023-04-28T01:00:07Z")

</div>

Hmm, let me try reinstalling it again. Btw, this `show_urls` method is so cool, thanks!

---

<div class="post-metadata">

**Author:** ![coder1](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/coder1/32/13466_2.png) [@coder1](https://forum.djangoproject.com/u/coder1)\
**Post date:** [April 28, 2023, 2:39am UTC](https://forum.djangoproject.com/t/social-google-oauth-2-0-authentication/20574/12 "2023-04-28T02:39:03Z")

</div>

`allauth.socialaccount.providers.google',` is in my`INSTALLED_APPS` list. So I am not sure what went wrong. But I think you might be on the right track.  
After I reinstalled it and I got a different error. It’s coming from the files from allauth:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/djangoproject/original/2X/1/17e398c2e29b6d38ea695b4158f565c459b63aa7.png)

---

<div class="post-metadata">

**Author:** ![coder1](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/coder1/32/13466_2.png) [@coder1](https://forum.djangoproject.com/u/coder1)\
**Post date:** [April 28, 2023, 2:47am UTC](https://forum.djangoproject.com/t/social-google-oauth-2-0-authentication/20574/13 "2023-04-28T02:47:35Z")

</div>

Hmm, the error above occurred because I changed the path to `path('accounts/', include('allauth.urls')),`, and now that I changed the path back to `path('', include('allauth.urls')),`, it’s this error again. Quite interesting.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/djangoproject/original/2X/a/a206261eb2782b431e9103827c15d504f86c5cd2.png)

---

<div class="post-metadata">

**Author:** ![bharasagarn](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/bharasagarn/32/13587_2.png) [@bharasagarn](https://forum.djangoproject.com/u/bharasagarn)\
**Post date:** [May 5, 2023, 10:24pm UTC](https://forum.djangoproject.com/t/social-google-oauth-2-0-authentication/20574/14 "2023-05-05T22:24:30Z")

</div>

Found anything on this? I’m also facing the same.

---

<div class="post-metadata">

**Author:** ![coder1](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/coder1/32/13466_2.png) [@coder1](https://forum.djangoproject.com/u/coder1)\
**Post date:** [May 6, 2023, 9:22pm UTC](https://forum.djangoproject.com/t/social-google-oauth-2-0-authentication/20574/16 "2023-05-06T21:22:53Z")

</div>

Nope. Taking a break on this. But let me know if you found a solution…

---

<div class="post-metadata">

**Author:** ![tohid4n](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/tohid4n/32/14992_2.png) [@tohid4n](https://forum.djangoproject.com/u/tohid4n)\
**Post date:** [July 25, 2023, 12:48pm UTC](https://forum.djangoproject.com/t/social-google-oauth-2-0-authentication/20574/17 "2023-07-25T12:48:30Z")

</div>

Today I have faced a similar problem.

I tried everything, but nothing worked, so I deleted OAuth 2.0 Client and created a new one.  
Added client\_id and client\_screat

SOCIALACCOUNT\_PROVIDERS = {  
‘google’: {  
‘SCOPE’: [‘email’],  
‘AUTH\_PARAMS’: {‘access\_type’: ‘online’},  
‘OAUTH\_PKCE\_ENABLED’: True,

```
    'APP': {
        'client_id': env('CLIENT_ID'),
        'secret': env('SECRET'),
    }
}

```

}

Now everything works well.

go and create new credentials and add them to your SOCIALACCOUNT\_PROVIDERS

> **[Google Cloud Platform](https://accounts.google.com/v3/signin/identifier?dsh=S302535087%3A1690289001155923&continue=https%3A%2F%2Fconsole.cloud.google.com%2Fapis%2Fcredentials&followup=https%3A%2F%2Fconsole.cloud.google.com%2Fapis%2Fcredentials&ifkv=AeDOFXjv7nXmdn4QHdcTCITcVY8ejvlDFILpGLa12VxD-_D17d8Cbo8Z2e5LWB9YXzJRcUTkZ3tE&osid=1&passive=1209600&service=cloudconsole&flowName=GlifWebSignIn&flowEntry=ServiceLogin)**
>
> Google Cloud Platform lets you build, deploy, and scale applications, websites, and services on the same infrastructure as Google.

have a good time.

---

<div class="post-metadata">

**Author:** ![nikhilkenvetil](https://avatars.discourse-cdn.com/v4/letter/n/d9b06d/32.png) [@nikhilkenvetil](https://forum.djangoproject.com/u/nikhilkenvetil)\
**Post date:** [November 11, 2023, 2:51am UTC](https://forum.djangoproject.com/t/social-google-oauth-2-0-authentication/20574/18 "2023-11-11T02:51:08Z")

</div>

Yea well this worked for me!

---

<div class="post-metadata">

**Author:** ![kathanpatel0901](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kathanpatel0901/32/18801_2.png) [@kathanpatel0901](https://forum.djangoproject.com/u/kathanpatel0901)\
**Post date:** [January 29, 2024, 10:20am UTC](https://forum.djangoproject.com/t/social-google-oauth-2-0-authentication/20574/19 "2024-01-29T10:20:50Z")

</div>

you can try this  
in settings.py set  
SITE\_ID = 2
