Social Login Implementation \ Setup
You will first discover how to setup your database in order to store the user_token
.
That token uniquely identifies each user, allows you to recognize returning users on subsequent logins
and can be used with our User API.
Then you will have to add a simple callback
script to your system in order to retrieve the user's
social network profile data and use that data to register a new user account or log the user in.
- A database with a user table that has a row for each user.
- Each user has a unique user identifier (Usually the primary key of the table).
- Each user has a login (username or email) and a password to login with.
- A registration page on your website.
- New users can join your website by filling out a form on your registration page.
- A login page on your website.
- Users can login to their account by entering their credentials on the login page.
- After having logged in, your system creates a new session and stores the user's identifier.
If the setup of your website is different, you should still be able to follow this guide, some sections may however not be relevant for you.
1. Add the required table to your database.
You first of all have to add a new table to your database. For MySQL you can use a table like in our example below. You may have to tweak it slightly if you represent your internal user identifiers differently.
-- Table Structure CREATE TABLE `oneall_user` ( `user_id` INT(10) UNSIGNED NOT NULL , `user_token` CHAR(36) NOT NULL ) ENGINE = InnoDB; -- Table Indexes ALTER TABLE `oneall_user` ADD PRIMARY KEY (`user_id`), ADD UNIQUE KEY `user_link` (`user_id`,`user_token`), ADD UNIQUE KEY `user_token` (`user_token`);
The user_id
is the id that uniquely identifies user entries in your users table - feel free to rename the column at your convenience.
The user_token
uniquely identifies social network users, you will obtain it from our API after a user has logged in with
his social network account.
When you receive a user_token
from our API, you can match it against this table to check whether the social network account
is already linked to a user account in your proprietary system or not. If you find a match for the user_token
, then you can use
the user_id
to lookup the user record in your users table.
2. Implement the functions to access the data storage.
You should add the following functions to your system. Please note that these are only examples, you have to implement them depending upon your own system and database.
Return the proprietary user_id
linked to a given user_token
/* * Returns the proprietary user_id for user_token received by OneAll. * The goal is to check if there is an existing user account for a user_token received by OneAll. */ function get_user_id_for_user_token (user_token){ // Example Query: SELECT user_id FROM oneall_user WHERE user_token = <user_token> // Return the user_id or null if none found. }
Return the user_token
linked to a given proprietary user_id
/* * Returns the OneAll user_token for a proprietary user_id. * The goal is to check if the given user has already been linked to a OneAll user_token. */ function get_user_token_for_user_id (user_id){ // Example Query: SELECT user_token FROM oneall_user WHERE user_id = <user_id> // Return the user_token or null if none found. }
Create a link between a user_token
an a proprietary user_id
/* * Links a OneAll user_token to a proprietary user_id. * The goal is to store the user_token for a given user_id so that you can can recognize the user on subsequent logins. */ function link_user_token_to_user_id (user_token, user_id){ // Example: INSERT INTO oneall_user SET user_token = <user_token>, user_id = <user_id> }
3. Create a basic callback script.
After a successfully authentication with a social network, the OneAll API redirects the user to your
callback script and includes a connection_token
as POST
data. That token can
then be used to retrieve the user's social network profile data.
Now create a file with the code below on your server:
<?php // Check if we have received a connection_token if ( ! empty ($_POST['connection_token'])) { echo "Connection token received: ".$_POST['connection_token']; } else { echo "No connection token received"; }
Once you have created the file, you should be able to open it in your browser and you should see the message No connection token received.
Please keep the complete URL that points to this file handy as it will be used during the next steps of the guide. In the setup guide the link to this file is called callback_uri
.
Your database should now be ready and you should have setup a basic version of the callback script.