Facebook oauth redirect does not work in iframe

facebookiframeoauth

Recently I noticed that my applications on Facebook stopped to work properly.

When someone opens app who did not authorize in yet I display simple content with link,
When link is clicked, in application I issue redirect (in Spring I return "redirect:…url..") to URL:

https://www.facebook.com/dialog/oauth?scope=email&client_id=317651918315301&redirect_uri=https%3A%2F%2Fapps.facebook.com%2Facnestop&scope=email&response_type=token

it sends 302 with given location to iFrame.

Then blank iFrame is displayed, and following headers from FB are returned:

Cache-Control   private, no-cache, no-store, must-revalidate
Connection  keep-alive
Content-Encoding    gzip
Content-Type    text/html; charset=utf-8
Date    Fri, 25 May 2012 10:37:11 GMT
Expires Sat, 01 Jan 2000 00:00:00 GMT
P3P CP="Facebook does not have a P3P policy. Learn why here: http://fb.me/p3p"
Pragma  no-cache
Set-Cookie  _e_1vFX_0=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; path=/; domain=.facebook.com; httponly locale=pl_PL; expires=Fri, 01-Jun-2012 10:37:11 GMT; path=/; domain=.facebook.com wd=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; path=/; domain=.facebook.com; httponly
Transfer-Encoding   chunked
X-Content-Type-Options  nosniff
X-FB-Debug  VYI+cCm/Vfpx3US82n06uFuw5gF6UQDg+8GUSpGUL9A=
X-Frame-Options DENY
X-XSS-Protection    0
x-content-security-policy...    allow *;script-src https://*.facebook.com http://*.facebook.com https://*.fbcdn.net http://*.fbcdn.net *.facebook.net *.google-analytics.com *.virtualearth.net *.google.com 127.0.0.1:* *.spotilocal.com:*;options inline-script eval-script;report-uri https://www.facebook.com/csp.php

And just blank iFrame is displayed.

When URL which I redirect to is pasted to browser directly – it displays Facebook prompt to authorise app.

Any ideas why behavior is different when iFrame is redirected from pasting and opening same link in browser?

I noticed this today, previously app was working fine.

This is my sample app:
https://apps.facebook.com/acnestop/

Best Answer

If the user has not authorized your application, you need not handle that, facebook takes care of that.

But handling the case where a user has not logged in you can use getLoginURL

$loginUrl = $facebook->getLoginUrl(
    array(
        'scope'         => 'email,user_checkins,etc',
        'redirect_uri'  => 'https://apps.facebook.com/my-application/' 
    )
);

Do not forget the trailing slash in redirect_uri

Hope this helps

Related Topic