jgorset/fandjango — Issue #49: Redirect uri not generated properly for canvas not pointing to root
Author: fhlawaczek
Created: 2012-02-10 17:35:53+00:00
State: open

Let me clarify:
In the `facebook_authorization_required` decorator, you construct the `redirect_uri` with the following code:

```redirect_uri = redirect_uri or 'http://%(domain)s/%(namespace)s%(url)s' % {
'domain': FACEBOOK_APPLICATION_DOMAIN,
'namespace': FACEBOOK_APPLICATION_NAMESPACE,
'url': request.get_full_path()
}```

So, for example, if the decorated view's url is `http://myapp.com/foo/bar/`, the url to go to after authentication will be `http://apps.facebook.com/myapp/foo/bar`
The problem arises when the canvas is not pointed to the root of the site (i.e. `http://myapp.com/`) but to a path like `http://myapp.com/foo/`.
In that case, `http://apps.facebook.com/myapp/foo/bar` will try to get `http://myapp.com/foo/foo/bar/` in the canvas iframe, which is incorrect.

My humble suggestion is to add a configuration setting like `FACEBOOK_APPLICATION_LOCAL_ROOT` and simply strip that string from the left of the `request.get_full_path()`.
Something like:
```url = request.get_full_path()
url = url.startswith(FACEBOOK_APPLICATION_LOCAL_ROOT) and url.replace(FACEBOOK_APPLICATION_LOCAL_ROOT, '', 1) or url```

Maybe that's not the best solution but I couldn't figure out a way of programmatically guess what's the app root on the server side.

Hope this is understandable.

This is a great app for Django and I'm using it in some experiments and maybe in a production project soon.