0

I'm using OSQA and I simply trying to login with Facebook (without any change on the platform code), only setting 'app secret' and 'app id'.

My Facebook App settings:

Site URL: http://localhost:8080/osqa/
Canvas URL: http://localhost:8080/osqa/osqa/account/facebook/done/

I encounter this error:

{
   "error": {
      "message": "Invalid redirect_uri: Given URL is not allowed by the Application configuration.",
      "type": "OAuthException",
      "code": 191
   }
}

and this is the url with the redirect_uri

https://graph.facebook.com/oauth/authorize?scope=email&redirect_uri=http%3A%2F%2F127.0.0.1%3A8080%2Fosqa%2Fosqa%2Faccount%2Ffacebook%2Fdone%2F&client_id=***

I read a lot of posts concerning this problem here on stackoverflow and in other forums, I know there is a simple solution, but cannot figure out yet.

Massimo Variolo
  • 4,669
  • 6
  • 38
  • 64

1 Answers1

2

The redirect in your URL translates to this:

redirect_uri=http://127.0.0.1:8080/osqa/osqa/account/facebook/done/

Facebook just checks the strings and sees that 127.0.0.1 is not the same as localhost. So replace this in your app settings and the redirect should work.

Jan Gerlinger
  • 7,361
  • 1
  • 44
  • 52
  • It gives me back a 404 with this URL "http://127.0.0.1:8080/osqa/osqa/account/facebook/done/?code=***" I delete one occurence of osqa/ and works well. Now I must figure out how to solve the new problem – Massimo Variolo Aug 09 '12 at 21:04
  • Check your `APP_URL` setting in `settings_local.py`. Pay attention to the comment above: `# This shouldn't be followed by a trailing slash.` – Jan Gerlinger Aug 09 '12 at 21:28
  • APP_URL = 'http://127.0.0.1:8080/osqa' If I delete "/osqa" I obtain an unuseless URL "http://127.0.0.1:8080/account/facebook/done/?code=***" Maybe is a bug somewhere else? – Massimo Variolo Aug 09 '12 at 21:35
  • On urls.py I have: "url(r'^%s(?P\w+)/%s$' % (_('account/'), _('done/')), app.auth.process_provider_signin, name='auth_provider_done')," – Massimo Variolo Aug 09 '12 at 21:37
  • So if you delete `/osqa` one time from the `APP_URL` setting, it is removed twice from the `redirect_uri`? Try changing `_('done/')` to `_('done')`. – Jan Gerlinger Aug 09 '12 at 21:39
  • Yes. I've tried: "127.0.0.1:8080/osqa/osqa/account/facebook/done?code=***" instead of "127.0.0.1:8080/osqa/osqa/account/facebook/done/?code=***" – Massimo Variolo Aug 09 '12 at 21:45
  • In the method `process_provider_signin(request, provider)` from `url(r'^%s(?P\w+)/%s$' % (_('account/'), _('done/')), app.auth.process_provider_signin, name='auth_provider_done'),` inside it there is `assoc_key = provider_class.process_authentication_request(request)`. The method `process_authentication_request(self, request):` has this line `args = dict(client_id=settings.FB_API_KEY, redirect_uri="%s%s" % (django_settings.APP_URL, request.path))` Maybe this last line is the problem. – Massimo Variolo Aug 09 '12 at 21:54
  • 1
    Yeah, this is probably a bug there. You could try fix it, or as a dirty workaround hardcode your `redirect_uri` there ;) As you're `APP_URL` contains only one `/osqa` there is probably a `/osqa` to much in `request.path`. – Jan Gerlinger Aug 09 '12 at 21:55
  • 1
    Here is the solution for the second problem ;) http://meta.osqa.net/questions/11746/facebook-login-bug-in-subfolder-install-subfolder-part-of-url-appears-twice-during-login-redirect – Massimo Variolo Aug 09 '12 at 22:48