st4lk / django-rest-social-auth

OAuth signin with django rest framework
MIT License
522 stars 122 forks source link

Trying to login and redirect to state. Error: "Redirect URI doesn't match original redirect URI" #92

Open Martin317 opened 5 years ago

Martin317 commented 5 years ago

Hello. In my Angular app I have a login page and some states.

My objective is:

When I go to some state (e.g. /inicio) and I am not logged in, there are a AuthGuard, It redirect to /login state with a param "returnUrl" (https://localhost:4200/login/?returnUrl=/inicio). Login state try to login with instagram with this url: "https://api.instagram.com/oauth/authorize/?client_id=<myclientid>&scope=public_content&hl=en&response_type=code&redirect_uri=" + window.location.origin + "/login/?returnUrl=" + this.returnUrl;"

In this example:

https://api.instagram.com/oauth/authorize/?client_id=<myclientid>&scope=public_content&hl=en&response_type=code&redirect_uri=https://localhost:4200/login/?returnUrl=/inicio

On instagram API I have this url:

https://localhost:4200/login/

On my server I have this:

REST_SOCIAL_OAUTH_ABSOLUTE_REDIRECT_URI = 'https://localhost:4200/login/?returnUrl=/inicio'

It works. But I need a variable returnUrl, becouse I need to redirect to /state/<some_id> I try with this: REST_SOCIAL_OAUTH_ABSOLUTE_REDIRECT_URI = 'https://localhost:4200/login/?returnUrl' REST_SOCIAL_OAUTH_ABSOLUTE_REDIRECT_URI = 'https://localhost:4200/login/?returnUrl=' REST_SOCIAL_OAUTH_ABSOLUTE_REDIRECT_URI = 'https://localhost:4200/login/' REST_SOCIAL_OAUTH_ABSOLUTE_REDIRECT_URI = 'https://localhost:4200/login'

but it didn't work, always the same error: Authentication process canceled; ; {'error_type': 'OAuthException', 'code': 400, 'error_message': "Redirect URI doesn't match original redirect URI"} Some idea? Thanks.

st4lk commented 5 years ago

@Martin317 You can include the redirect_url param when you are calling backend API. In that case backend will use it in API request. From readme:

At input there is also non-required field redirect_uri. If given, server will use this redirect uri in requests, instead of uri got from settings. This redirect_uri must be equal in front-end request and in back-end request. Back-end will not do any redirect in fact.

Does it help?

Martin317 commented 5 years ago

Thank you!! It seems to work. I had not read that.