PHPBB33 + Facebook Login creates account automatically

Discussion forum for Extension Writers regarding Extension Development.
Post Reply
tyrannotorus
Registered User
Posts: 9
Joined: Thu May 15, 2014 7:02 pm

PHPBB33 + Facebook Login creates account automatically

Post by tyrannotorus » Thu May 15, 2014 7:21 pm

Hi guys,

I have phpBB-3.1.0-b3 installed and it's set up using OAuth for facebook, which adds a facebook icon to the login screen, and everything works as it should.

However, I want to restrict the forum to only facebook logins. When you log-in with your facebook account, it will automatically create your forum account based on your facebook profile data. I can autocreate a new forum account in ucp_login_link.php if the user logs in with a facebook account that is unlinked...

Code: Select all

if (!$login_link_error)
{
	$user_row = array(
    		'username'              => 'New Facebook User ',
    		'user_password'         => phpbb_hash('password'),
    		'user_email'            => 'email@email.com',
    		'group_id'              => 4,
    		'user_type'             => 0,
    	);
	$user_id = user_add($user_row);
}
But, how do I populate the the array with data from the facebook profile? Where is the data that is returned from facebook when you use the phpBB3.1 facebook oauth feature?

Pony99CA
Registered User
Posts: 4783
Joined: Thu Sep 30, 2004 3:13 pm
Location: Hollister, CA
Name: Steve
Contact:

Re: PHPBB33 + Facebook Login creates account automatically

Post by Pony99CA » Sat May 17, 2014 1:45 am

I don't know for sure (I've never used OAuth), but I presume that you send it a user name and password and it basically replies with a Yes/No response letting you know whether the user name and password matched or not. I would be surprised if it returned the password or E-mail address to you. That could be a privacy nightmare.

In other words, OAuth sounds like an authorization protocol, not a registration system.

That said, you've already got the username and password on the login form, the group_id would be the Registered Users group and the user_type would be whatever the default user type is (check the code). The only difficulty you'd have is the E-mail address, but if the OAuth succeeded, you could probably pop up a window asking for his E-mail address.

Even better would be to take the user to the registration agreement and then the registration page with the existing information filled in. The user would enter his E-mail address and the default registration code would add the user for you.

Steve
Silicon Valley Pocket PC (http://www.svpocketpc.com)
Creator of manage_bots and spoof_user (ask me)
Need hosting for a small forum with full cPanel & MySQL access? Contact me or PM me.

tyrannotorus
Registered User
Posts: 9
Joined: Thu May 15, 2014 7:02 pm

Re: PHPBB33 + Facebook Login creates account automatically

Post by tyrannotorus » Tue May 20, 2014 12:41 pm

Hey, thanks for the reply.

I actually downgraded to 3.0.12 stable and am not using the phpbb facebook oauth anymore. Making use of the horrible examples at https://developers.facebook.com/docs/ph ... rted/4.0.0, I've been able to prompt the user to login into facebook, and retain the user's facebook data after the redirect.

I just need to decipher the phpbb login flow and find out where to implement it.

techblogcorner
Registered User
Posts: 3
Joined: Wed May 14, 2014 6:58 pm
Contact:

Re: PHPBB33 + Facebook Login creates account automatically

Post by techblogcorner » Tue May 20, 2014 7:44 pm

tyrannotorus wrote:Hey, thanks for the reply.

I actually downgraded to 3.0.12 stable and am not using the phpbb facebook oauth anymore. Making use of the horrible examples at https://developers.facebook.com/docs/ph ... rted/4.0.0, I've been able to prompt the user to login into facebook, and retain the user's facebook data after the redirect.

I just need to decipher the phpbb login flow and find out where to implement it.
Hi, this is just quite interesting thing you asked in forum, as i am seeing this too, as i am new user for phpbb forum 3.1 version. very keen to know the exact result if you implemented this and it works. please reply here as i am going to follow the same steps as you will do for it. ;)

tyrannotorus
Registered User
Posts: 9
Joined: Thu May 15, 2014 7:02 pm

Re: PHPBB33 + Facebook Login creates account automatically

Post by tyrannotorus » Tue May 27, 2014 9:23 pm

I did it, but it's awful to explain.

The facebook auth code is essentially this
http://stackoverflow.com/questions/2341 ... al-example

And the login flow in phpbb follows these functions.
ucp.php?mode=login
functions.php login_box()
auth.php login()
auth_db.php login_db()

Destabilizator
Registered User
Posts: 9
Joined: Sat Jun 20, 2015 4:03 pm

Re: PHPBB33 + Facebook Login creates account automatically

Post by Destabilizator » Sun Jun 21, 2015 10:07 am

any chance you'd share further details of your solution?

User avatar
javiexin
Code Contributor
Posts: 1157
Joined: Wed Oct 12, 2011 11:46 pm
Location: Madrid, Spain
Name: Javier
Contact:

Re: PHPBB33 + Facebook Login creates account automatically

Post by javiexin » Sun Jun 21, 2015 2:33 pm

Destabilizator wrote:any chance you'd share further details of your solution?
Forget it, this topic is over a year old, and the person you are asking the question to has not been active for almost as much.

Destabilizator
Registered User
Posts: 9
Joined: Sat Jun 20, 2015 4:03 pm

Re: PHPBB33 + Facebook Login creates account automatically

Post by Destabilizator » Sun Jun 21, 2015 3:25 pm

javiexin wrote:
Destabilizator wrote:any chance you'd share further details of your solution?
Forget it, this topic is over a year old, and the person you are asking the question to has not been active for almost as much.
Ya well, he did the closest thing to what I need and I can't contact him because I have less than 5 posts :D

Destabilizator
Registered User
Posts: 9
Joined: Sat Jun 20, 2015 4:03 pm

Re: PHPBB33 + Facebook Login creates account automatically

Post by Destabilizator » Thu Jun 25, 2015 7:50 am

So I did it! I still can't believe that there is no extension for this...

Basically what you need to do, is turn on OAuth via Facebook, so users can link their accounts to FB.
Then, if user tries to link with FB, but is not registered on the forum yet, automatically register him, instead of asking user to do it.

I use user's FB name (replace spaces with dots and cut it to 20 chars) and e-mail.
Function perform_auth_login() from <forum root>/phpbb/auth/provider/oauth/service/facebook.php gets this info, but doesn't return it (gives only FB ID), so I've modified it to return array with all the details (and corrected calls of this function from other locations).
Then all I needed was https://wiki.phpbb.com/Add_users to add user to database and then call link_account() after the user was added.
At last, you need to fake $row (which would be user data when it checks, if the user is already in database), so the code can continue unchanged. It just needs to be array with user_id, which is returned after you call user_add(). (this all happens in <your forum root>/phpbb/auth/provider/oauth/oauth.php)

I know this is more of a hack than proper approach, so feel free to advice cleaner solution 8-)

Pony99CA
Registered User
Posts: 4783
Joined: Thu Sep 30, 2004 3:13 pm
Location: Hollister, CA
Name: Steve
Contact:

Re: PHPBB33 + Facebook Login creates account automatically

Post by Pony99CA » Sat Jun 27, 2015 2:28 am

Destabilizator wrote:So I did it! I still can't believe that there is no extension for this...

Basically what you need to do, is turn on OAuth via Facebook, so users can link their accounts to FB.
Then, if user tries to link with FB, but is not registered on the forum yet, automatically register him, instead of asking user to do it.

I use user's FB name (replace spaces with dots and cut it to 20 chars) and e-mail.
Function perform_auth_login() from <forum root>/phpbb/auth/provider/oauth/service/facebook.php gets this info, but doesn't return it (gives only FB ID), so I've modified it to return array with all the details (and corrected calls of this function from other locations).
Then all I needed was https://wiki.phpbb.com/Add_users to add user to database and then call link_account() after the user was added.
At last, you need to fake $row (which would be user data when it checks, if the user is already in database), so the code can continue unchanged. It just needs to be array with user_id, which is returned after you call user_add(). (this all happens in <your forum root>/phpbb/auth/provider/oauth/oauth.php)

I know this is more of a hack than proper approach, so feel free to advice cleaner solution 8-)
You might want to try making this an Extension (if possible).

I'm also curious how you handle name collisions. For example, your Facebook name is JimBob, but there's already another JimBob on the board. Or is your board new and you'll only allow Facebook registrations?

Steve
Silicon Valley Pocket PC (http://www.svpocketpc.com)
Creator of manage_bots and spoof_user (ask me)
Need hosting for a small forum with full cPanel & MySQL access? Contact me or PM me.

Destabilizator
Registered User
Posts: 9
Joined: Sat Jun 20, 2015 4:03 pm

Re: PHPBB33 + Facebook Login creates account automatically

Post by Destabilizator » Sun Jun 28, 2015 2:21 pm

I am not handling name collisions, because my board is not English and chances of them happening are close to none (our names are weird enough that nobody uses them as nicknames :D).
My board is new and the reason why I went through this whole endeavour was that users couldn't be arsed to register via normal way...

User avatar
forashish
Registered User
Posts: 65
Joined: Mon Apr 25, 2016 9:52 am
Location: India

Re: PHPBB33 + Facebook Login creates account automatically

Post by forashish » Sat May 28, 2016 10:41 pm

That solution seems quite tedious to me. Any simpler approach please :)

User avatar
asouza
Registered User
Posts: 6
Joined: Tue Jan 19, 2016 3:28 pm

Re: PHPBB33 + Facebook Login creates account automatically

Post by asouza » Sun May 29, 2016 1:03 am

someone got something more "easy" to create login with "facebook login" without the user needs register before and after still do the facebook connection?
(I don't want use the oneall extension)

Post Reply

Return to “Extension Writers Discussion”