ZenphotoCMS Forum
Facebook federated login - Printable Version

+- ZenphotoCMS Forum (https://forum.zenphoto.org)
+-- Forum: Support (https://forum.zenphoto.org/forum-1.html)
+--- Forum: Plugins (https://forum.zenphoto.org/forum-6.html)
+--- Thread: Facebook federated login (/thread-10340.html)



Facebook federated login - BigLouis87 - 28-08-2012

Is there a way to implement the Facebook login into the federated login plugin? I have to do it but I have no idea how to do this. I think Facebook is today the most social login used, so it should be added among Google, OpenID, Yahoo and others.
Thanks




Facebook federated login - acrylian - 28-08-2012

Possible is nearly everything. The reason it is not in there is that both the developer of it and I don't have FB accounts (the FB page is run by a non developing team member for us).




Facebook federated login - sbillard - 28-08-2012

Last time we looked Facebook did not provide an open-id login interface. Maybe that has changed. If so adding Facebook would be simple. If there needs to be some sort of API and a handler for federated logon would need to be written to that API.




Facebook federated login - BigLouis87 - 29-08-2012

I searched a bit and found that Facebook uses OAuth 2.0 for login, so federated plugin cannot be used. Its social plugin, using JS SDK, seems to simplify the work, but I haven't understood well how it works.
I think it passes to the desired page (for example register.php) an array with the user information, userid, email, name and a token (a useful how-to can be found here http://tinyurl.com/ch7z2n7 ).
Now, how can I handle this data to interface with ZP? Should I create a new page (plugin?) to simply send this data to the ZP registration system or should I use the object model from scratch?




Facebook federated login - acrylian - 29-08-2012

You should maybe take a look at the Twitter plugin which if I recall right also uses OAuth. Probably you can adapt it to do the same or similar for FB.

To your last question you will need the object model in any case anyway. For example to get the current logged in admin users so you know which one to log in with. Since ZP can have multiple admins.




Facebook federated login - BigLouis87 - 29-08-2012

uhm, I looked to the twitter plugin and it uses OAuth, but it seems a quite complex way to proceed for me.
I will try to use the Javascript SDK provided by facebook and call directly the register_user plugin as the register form do, following the tutorial I posted in my last reply.
Probably the author of twitter plugin will be able to adapt it in some minute and it will be appreciated by lots of users, but I have no idea how it works, it's a too long and complex code for me.




Facebook federated login - sbillard - 29-08-2012

The twitter plugin uses OAuth to log into facebook. What you want is sort of the reverse--if someone is logged into facebook then you want to grant him Zenphoto authorization.

If OAuth has the ability to query facebook for the currently logged in user then you would want to build a federated login "handler" that would deal with that.

The following is a simple script for logging into Zenphoto "from the outside".

`




Facebook federated login - acrylian - 30-08-2012

Quote:The twitter plugin uses OAuth to log into facebook.
Into Twitter of course..;-)




Facebook federated login - BigLouis87 - 01-09-2012

Thanks Stephan, I studied your script and understood that its core is the static function federated_logon::credentials.
Using the facebook php sdk I solved the fb auth part, so I finally have an array with user data; my idea was passing this data to the federated logon:
if (fb user logged in) federated_logon::credentials('fb:'.$user_profile['id'], NULL, $user_profile['name'], $redirect);
I made this a plugin; it partially worked, but even if it create the user and log in (if I go to /admin on top I can see "fb:xxxxxxxxx" as the username), the $_zp_current_admin_obj object is NULL so other functions that use this object don't recognize the user as logged in.
Is this a normal behaviour using federated_logon::credentials? How can I fix this?
I load this function calling it in the plugin with zp_register_filter('theme_head', 'FBloginHeader');, is this correct?
Thanks




Facebook federated login - sbillard - 01-09-2012

Two things:

First, federated_logon::credentials returns a result that may be an error message, so you should be sure that you are not getting some kind of logon error.

Second, Logon needs to happen sooner than the theme head. If you are not going to make this a federated login handler then you will have to attach to the load_theme_script filter. Even this may not work, so the best approach is to make the FB logon a federated logon handler.




Facebook federated login - BigLouis87 - 01-09-2012

You're right! Attaching it to the load_theme_script worked.
This is the simple way to obtain the login:
//including facebook php sdk require_once ('...../facebook.php'); //Creating our application instance $facebook = new Facebook(array( 'appId' => $appid, 'secret' => $secretappid )); //Get User ID $FBuser = $facebook->getUser(); if ($FBuser) if (!$_zp_current_admin_obj){ try { // Proceed knowing you have a logged in user who's authenticated. $user_profile = $facebook->api('/me'); federated_logon::credentials('fb:'.$user_profile['id'], NULL, $user_profile['name'], $redirect); } catch (FacebookApiException $e) { error_log($e); $FBuser = null; echo $e; } }
Caling the login/logout link with
if ($FBuser) { echo "getLogoutUrl($params = array('next' => $redirect))."\">Logout from FB"; } elseif (!zp_loggedin()) { echo "getLoginUrl($params = array('redirect_uri' => $redirect))."\">Login with FB"; }
However it has some issues for the logout, so it would be a cleaner way making a federated logon handler. Have you got some documentation for the federated logon or at least some tips to give me to understand the mechanism and to integrate this handler? I found this plugin very complex to read...
Thanks




Facebook federated login - sbillard - 01-09-2012

What are the issues with logout? Really the only difference between what you have done and what would happen with a federated_logon handler is that would be executed only during a logon request. (But of course that may be the issue--pretty hard to log out if the page refresh logs you back in!)

Anyway, the above script is the best example of a simplified federated_logon handler. Also, the individual handlers supplied are not so complicated if you ignore the OpenID_try_auth.php script. What that does is handle the communication for authentication. Your code replaces that. Google and Yahoo handle the whole transaction "off line" to Zenphoto, so there is no code other than making the connection. Verisign on the other hand only provides a "verification" so the handler has to show the verification result and allow for a redirect back to Zenphoto. What you need to do depends on how Facebook behaves.

It would appear that the difference in what you have already done and what is needed would be to handle the case where the user was not currently logged in to Facebook.




Facebook federated login - BigLouis87 - 02-09-2012

The issues with logout was of course that the page re-login me in on a page refresh after a logout, as you said, but I was aware of it, what I wrote was only a simple try to check if it worked.
During these days I will try to adapt it following your advices and let you know.
Thanks again!




Facebook federated login - micheall - 04-09-2012

Nice to see someone working on this and that it's got some progress, good work BigLouis87!




Facebook federated login - callimaco - 10-04-2013

Hi. There are news for this "project" or implementation?

Thanks!




Facebook federated login - acrylian - 10-04-2013

If there were you would find it on our extensions section. So in short, no.




Facebook federated login - jphilbert - 10-04-2013

I am actually working on one and will add it to zenFBSuite




Facebook federated login - acrylian - 10-04-2013

Good to hear...;-)