php - Database structure for social login implementation? -
in application, have "user" table have following structure.
create table if not exists `users` ( `userid` int(10) unsigned not null auto_increment, `username` varchar(128) not null default '', `password` varchar(32) not null default '', `email` text not null, `newsletter` tinyint(1) not null default '0', `banned` enum('yes','no') not null default 'no', `admin` enum('yes','no') not null default 'no', `signup_ip` varchar(20) not null default '', `activation_key` varchar(60) not null default '', `resetpassword_key` varchar(60) not null default '', `createdon` datetime not null default '0000-00-00 00:00:00', primary key (`userid`) ) engine=myisam default charset=latin1 auto_increment=27 ;
i want implement social login via facebook, twitter , openid in application, statckoverflow did. please suggest me change require in db , how logic implemented in php, alongside existing login facility.
thanks!
i suggest introduce concept of authenticationprovider
:
create table if not exists `authenticationprovider` ( `providerkey` varchar(128) not null, `userid` int(10) unsigned not null, `providertype` enum('facebook','twitter', 'google') not null, primary key (`providerkey`) ) engine=myisam default charset=latin1;
each login provider provides unique key user. stored in providerkey
. providertype
contains information login provider providerkey
belongs to, , finally, userid
column couples information users
table. when receive succesful login 1 of login providers find corresponding providerkey
in table , use set authentication cookie user in question.
i'm not sure want providertype
enum
. more correct make table hold these.
when user first registers site, , logs in via facebook, example, have create row in users
table. however, there no password
, activation_key
, resetpassword_key
involved. may want move fields separate table, such users
table contains core user data, , no data relevant single login mechanism (username/password).
i hope makes sense , points in right direction.
/klaus
Comments
Post a Comment