13

I am using Google OAuth for my Django App (via allauth package)

I have followed all standard configuration steps. In Google Developer console here's what i have:

Authorized JavaScript origins

https://example.com  

Authorized redirect URIs

https://example.com/accounts/google/login/callback/ - login fails
http://example.com/accounts/google/login/callback/ - login succeeds

What i observe that if i have a https redirect URL in Authorized redirect URIs, it does not allow login and it fails with redirect_uri_mismatch Error. If i have a http redirect URL then the login succeeds.

What do i need to do to have a https enabled redirect URL ?

Prasanna
  • 1,617
  • 1
  • 17
  • 22

3 Answers3

26

Adding the following in production settings.py fixed the problem for me:

ACCOUNT_DEFAULT_HTTP_PROTOCOL='https'

Prasanna
  • 1,617
  • 1
  • 17
  • 22
  • Thank you. Somehow the same code works for my localhost but fail in production and this was the fix that got me out of it – Kim Stacks Dec 23 '20 at 15:42
  • Gave you a bounty to get you over 1k points. My way of saying thanks. Forgot to add that my social provider was GitHub so your QnA was the same issue with the same fix for me – Kim Stacks Dec 27 '20 at 05:48
  • 1
    Where did you find this setting? – E_K Nov 10 '21 at 03:51
  • This is very useful and very hidden. Where did you find it? Google OAuth wouldnt work without this. – John Jun 10 '22 at 19:37
1

**This worked for me :

  1. Go to https://console.developers.google.com
  2. Add without port http://127.0.0.1/accounts/google/login/callback/
  3. Also Add http://localhost/accounts/google/login/callback/
  4. see the image in the link for detail

image

griffins
  • 7,079
  • 4
  • 29
  • 54
0

In my case, the problem was in the following:

  1. My website switched the access to HTTPS-only connections, while in Google API dashboard was http://profile.example.com/accounts/google/login/callback/.
  2. So, I changed: from http -> https and it begins to work fine. enter image description here