Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google OAuth2 redirect_uri_mismatch Issue

All,

Im getting a 400 redirect_url_mismatch error upon attempting to authenticate through google. I'm using python-socal-auth through a django application to achieve this process.

Everything works smoothly, until I get to the final stages of the process where I hit a redirect_uri_mismatch issue.

On google, I receive this message.

"The redirect URI in the request: http://localhost:8000/something/complete/google-oauth2/ did not match a registered redirect URI"

`Request Details
from_login=1
scope=https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile
response_type=code
redirect_uri=http://localhost:8000/something/complete/google-oauth2/
state=qT1RLLMa72F8NxFFubHwCVe3GgLDNcgZ
as=-55f896f3314b21af
pli=1
client_id=160177117398
authuser=0
hl=en`

Included below is a screenshot of the client ID's redirect URI.

enter image description here

What am I doing wrong?

Thanks!

like image 724
user2714604 Avatar asked Apr 26 '14 16:04

user2714604


People also ask

What does Error 400 Redirect_uri_mismatch mean?

This is an error that comes up in the final step of adding the Client ID and Secret to SSA. This happens when the URL to your site is not typed in exactly right in the API console to the newly created Client ID and Secret. This is not your fault, Google is quite picky with the URL.

How do I fix OAuth error?

When a user tries to login after the session id is expired, the system throws the OAuth error. Solution: Typically, clearing the browser or device cache fixes the problem.

What should be the redirect URI in oauth2?

A redirect URI, or reply URL, is the location where the authorization server sends the user once the app has been successfully authorized and granted an authorization code or access token.


2 Answers

Make sure you added the social-auth in the urls.py as

url('', include('social.apps.django_app.urls', namespace='social')),

and on console.developers.google.com set the Authorized redirect URIs to http://localhost:8000/something/complete/google-oauth2/

like image 83
vmenezes Avatar answered Sep 29 '22 20:09

vmenezes


One thing to note here is that redirect url should be exactly same till the last trailing slash. In my case, it was like http://localhot:8000/something/complete/google-oauth2 This should have been
http://localhot:8000/something/complete/google-oauth2/ This resulted in redirect_uri_mismatch.

Also define http: and https: in the console for redirect url because redirect url generated by social auth still sends http regardless of ssl setting in your server.

like image 43
Imju Avatar answered Sep 29 '22 19:09

Imju