sahat / satellizer

Token-based AngularJS Authentication
https://satellizer-sahat.rhcloud.com
MIT License
7.85k stars 1.13k forks source link

400 Bad Request - Redirect URI doesn't match original redirect URI #1071

Open ikoonman opened 7 years ago

ikoonman commented 7 years ago

Hello

I have a project where front-end and server side resides on seperate domains in DEV (www.sandbox.local and api.sandbox.local) - PROD ENV would be similar for example www.acme.com and api.acme.com.

I keep getting this error returned from GuzzleHttp when issuing a server-side post to https://api.instagram.com/oauth/access_token. The redirectUri specified in $authProvider.instagram is exactly the same as what I specified on Instagram's API under "Valid Redirect Uri's". I have even ensured to urlencode the URL before posting it, but no success.

The POST is (details masked with 'xxx'):

POST /oauth/access_token HTTP/1.1
User-Agent: GuzzleHttp/6.0.1 curl/7.51.0 PHP/5.6.30
Content-Type: application/x-www-form-urlencoded
Host: api.instagram.com

client_id=xxx&client_secret=xxx&grant_type=authorization_code&redirect_uri=http%3A%2F%2Fapi.sandbox.local%2Fapi%2Finstagram&code=3xxxb

The Response is as follow:

HTTP/1.1 400 Bad Request
Content-Type: application/json
Cache-Control: private, no-cache, no-store, must-revalidate
Pragma: no-cache
Expires: Sat, 01 Jan 2000 00:00:00 GMT
Vary: Cookie, Accept-Language\r\nContent-Language: en
Date: Thu, 20 Apr 2017 07:56:41 GMT
Set-Cookie: rur=PRN; Path=/, csrftoken=vWz6Foi9bDIYuHK5Jp3fa7Z1mc5el02Q; expires=Thu, 19
-Apr-2018 07:56:41 GMT; Max-Age=31449600; Path=/; Secure
Connection: keep-alive
Content-Length: 114

{"error_type": "OAuthException", "code": 400, "error_message": "Redirect URI doesn't match original redirect URI
"}

Just for clarity - the Satellizer $authProvider URL property for Instagram points to api.sandbox.local endpoint, and redirectUri is www.sandbox.local.

Any assistance would be appreciated.

vishad-jain commented 7 years ago

Hi, I was also facing the same error and after some searching I wound that you have to add url with appending /oauth2callback/ and /oauth2callback with it under Authorised redirect URIs

it worked fine for me see if it works for you also

best of luck happy coding :)