0

What I do is,

I start by making a call with ajax to the controller/function "users/authenthicate"

This function get's the loginurl from the sdk and returns it to javascript wich does the window.open.href... sofar sogood.. I get directed to the facebook loginpage,

but after a successvol login, it redirects back to the same users/authenticate.

QUESTION: is this the normal behaviour? or can I set the redirecturl..

QUESTION: it returns the url without a slash between the questionmark so the function is never recognized like this "users/authenthicate?bladeblibla".

*I did set some url when I registred the application, but that was a completely different url something like "http://www.domain/users/facebook_login"*

thanks Richard

Richard
  • 4,516
  • 11
  • 60
  • 87

2 Answers2

1

You can set the redirect URI as follows:

$linkToOauthDialog = $this->facebook->getLoginUrl(

  array(
     'scope'         =>  SCOPE_OF_THE_APP,
     'redirect_uri'  =>  REDIRECT_URI
  )

);

You should also have in mind that Safari doesn't allow setting third party cookies in an iframe, that's why you need to redirect to your own domain first, where you set a cookie and redirect to facebook again. Otherwise you end up in an infinite loop.

I have described this method in more detail here: Safari 3rd party cookie iframe trick no longer working?

Community
  • 1
  • 1
Marcel Kalveram
  • 1,295
  • 1
  • 14
  • 22
  • hm, thanks, but I am not doing something with an iframe ,I think,..- it is a full page redirect like going to google and coming back -- I will try your solution.. – Richard Aug 08 '12 at 15:45
  • Oh, i see. I thought you were getting the auth dialog for a facebook application, which normally run in an iframe. – Marcel Kalveram Aug 08 '12 at 15:52
  • no, I needed it for authentication for a website, I am setting up all the authentications for all the providers, next is yahoo, because your solution worked like a charm. Now that I am handling al of those I was planning to use abrahams oauth library or do you now a better one that works with all off the oauths or do they all need specific handling? I also have lightopenid but it doesn't do the oauth..YAHOO also has it's own sdk..but is it really neccesary? – Richard Aug 08 '12 at 16:01
  • 1
    Unfortunately I don't have any experience with the way YAHOO handles OAuth authentification. Maybe this thread can point you in the right direction: http://stackoverflow.com/questions/76184/php-tutorial-for-openid-and-oauth – Marcel Kalveram Aug 08 '12 at 17:11
1

Yes, this is the default behaviour of the php sdk. When you call getLoginUrl() and you don't specify the redirect_uri at the param array, it will try to use the current url.

I think what you would want to use is the JS sdk's FB.login() method instead of redirects with window.open (will be opening popups trough but you will get information back in you page's js).

complex857
  • 20,425
  • 6
  • 51
  • 54
  • 1
    Oh, i guess i've only used the `window.location = 'new url';` format before. But then not sure then why would you get the login url from js then, why don't just send the user to the `users/authenticate` url and have it use http headers to do redirection. – complex857 Aug 08 '12 at 15:55
  • yes, now that you mention it, it would be better,does that work when you start with javascript to pass the name off the provider, I have to test some more..I think I set it up like this for debugging purposes, so I could see what values are being passed with firebug..it is more direct.. – Richard Aug 08 '12 at 16:44
  • I was also starting out with script that used the js sdk, but I found that out only later.. – Richard Aug 08 '12 at 16:59
  • I have to stay with jscript for the redirection if I start off with a xhr request otherwise only the ajax call will be redirected.. – Richard Aug 08 '12 at 17:34