- Basic Information Terminology, getting started and setting up your account. Recommended for new customers.
- Make your website social Step-by-step tutorials and information on how to integrate our plugins and services to your site.
- REST API Reference JSON/REST API for advanced social network integration. Must-read for developers.
Plugins: Guide \ Website Setup
This page is part of our step-by-step tutorial guide for integrating our Social Login and Social Link plugins into a web site that has already users with accounts.
In this part we will explain you how to setup your database to store the user_token
and how to add a simple callback script to your system.
- A database with a users table that has a row for each user:
- Each user has a unique userID (Usually the primary key of the user table);
- Each user has a login (username or email) and a password to login with.
- A sign-up page:
- New users can join your site by filling out a form on your sign-up page.
- A sign-in page:
- Existing users can login to their account by entering their credentials on the sign-in page;
- Users are authenticated based on their login/password;
- Once being logged in, you store the unique userID in a session.
- An account settings page:
- Authenticated users can change their account settings on this page.
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. Let's get started!
1. Setup your database
You first of all have to add a new table to your database. For MySQL you can use a table like this, but you may have to tweak it slightly if you use a different database or if you represent your internal user IDs differently:
CREATE TABLE `user_social_link` ( `id` INT( 10 ) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY , `user_id` INT( 10 ) UNSIGNED NOT NULL , `user_token` CHAR( 36 ) NOT NULL , UNIQUE ( `user_id` , `user_token` ) ) ENGINE = MYISAM ;
The user_id is the id that uniquely identifies users in your users table - you can rename the field according to 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 if you have already tied the social account
to a user account in your proprietary system or not.
If you use a layer of database-access code, you should expose the following functions to your application.
| Database Access Layer |
GetUserIdForUserToken(user_token)
SELECT user_id FROM user_social_link WHERE user_token = user_token;
|
GetUserTokenForUserId(user_id)
SELECT user_token FROM user_social_link WHERE user_id = user_id;
|
LinkUserTokenToUserId(user_token, user_id)
INSERT INTO user_social_link SET user_token = user_token, user_id = user_id;
|
UnlinkUserTokenFromUserId(user_token, user_id)
DELTE FROM user_social_link WHERE user_token = user_token AND user_id = user_id;
|
2. Setup your system
Create a new script on your server. If you use PHP, you might call it callback_handler.php
and use the code below. After a user has signed in/up through one of our plugins, he will be redirected to this script. The
script will then request the user's social network profile from our API.
<?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";
}
?>
Check if the script can be opened in your browser
The script has to be accessible through a public uri, i.e. http://www.yoursite.com/callback_handler.php.
You should see the message No connection token received when opening the script in your browser.
Please keep the URL to this script handy, it will be used lateron. In our guide we call it callback_uri.
3. Next Step
Continue with the integration of the Social Login Plugin.