“Social Auth” Documentation by “Hüseyin BABAL” v3.0


“Social Auth v3.0”

Created: 26/05/2012
By: Hüseyin BABAL
Email: turkiye.java@gmail.com

Thank you for purchasing my theme. If you have any questions that are beyond the scope of this help file, please feel free to email via my user page contact form here. Thanks so much!


Table of Contents

  1. Introduction
  2. Files In This Project
  3. How to Install
  4. Db Structure
  5. Changelogs
  6. Sources and Credits

A) Introduction - top

Social Auth is a script that helps you on authorizing your sign-in by using social networks.Your users do not have to use registration forms in order to register your system.You can get their information by let them sign-in by using social networks.This is very good thing for users and you. This script helps you on doing this things easily.You can do it by just adding some code snippets on your page.I will explain it with ordered steps below


B) Files In This Project - top

SocialAuth has following folder structure


C) How to Install - top

I will give an example on a sample project for successful script usage. Let's say you have a login page called "login.php". You have a callback page for session and callback operations after authorizing over social networks.It is called "callback.php".This time, user data is checked from DB and make some CRUID operations on DB. There is a good property on this version about login system. Those social authorization does not effect your current users' informations. There is also extra link on home page in order to redirect your actual login page. You have classes located under "src". Our main class file "SocialAuth.php" is also located here.And last thing is the config file, "configs.php" is located under "src"

  1. Configure Config File : There is configurations for each social network.Please configure this file according to your application. In order to connect database and make CRUID operations, you should also configure your DB credentials, table name, and field names in "configs.php"
  2. Session Check : Check session state on "login.php".You can do it with following code: if (empty($_SESSION)) { session_start(); }
  3. Include Main Class File : In order to use SocialAuth, you must add main class file "SocialAuth.php" include 'src/SocialAuth.php';
  4. Check Cookie : Check cookie inorder to learn if user logged-in or not.If Not logged-in, check action type. This means that check if there is any request for login over Facebook, Twitter, Linkedin, or Google. If user is not logged-in, check action whether user wants to logout or not. If user logged-in you won't show login buttons, otherwise you will show login buttons. If you want to login with facebook, you will use following; <a href="javascript:;" onclick="openLoginDialog('?action=login&type=twitter')">Login with Facebook</a> This will open a popup and parent window will be same. If you are logged-in and you want to logout, you can following; <a href="?action=logout">Logout</a> This will destroy all the sessions and you will authomatically logout

  5. Modify Callback Page : This page is called "callback.php" and you must check session state and you must include main class files.In this page first thing is to check where is request comes from. According to request source, we will do different session operations. After successfull authorizing, the system response user information object.If response come from facebook, you can use following code; case 'facebook': //Initialize facebook by using factory pattern over main class(SocialAuth) $facebookObj = SocialAuth::init('facebook'); $facebookInfo = $facebookObj->getUser(); if ($facebookInfo) { try { $url = ''; //Check if any field value specified in configs.php $fields = SocialAuth::getConfig('facebook', 'fields'); if (!empty($fields)) { $url = '?fields=' . $fields; } // Get detailed user info. $facebookUserInfo = $facebookObj->api('/me' . $url); /** * Prepare data inorder to send it to the complete registration page **/ $dataArr = array( 'type' => 'facebook', 'name' => $facebookUserInfo['name'], 'username' => $facebookUserInfo['username'], 'email' => $facebookUserInfo['email'] ); SocialAuth::redirectParentWindow('facebook', $dataArr, $_COOKIE['ref']); } catch (FacebookApiException $e) { error_log($e); $facebookInfo = null; } } break; Above code snippet gets user data response and redirect "index.php" with some url parameters.After redirecting index page, url parameters will be checked with session data and if it is equivalent, this data will be checked from db and by using this check a popup will be shown.User will input information like username, email, password and click "Complete Registration" button..After successful operation, page will be redirected to the callback page.If it fails, user will get an error messsage on popup page.
Finally, you can follow this steps or just use script as it is.Only things to do just configure configs.php according to your application and update html login buttons in "index.php".Also you can update "callback.php" if you want.

E) Db Structure - top

There are must be following columns on your database table. Field names can be configured from "configs.php";


F) Changelogs - top

There are some major changes on this version.You can see following;


G) Sources and Credits - top

I've used the following images, icons or other files as listed.


Once again, thank you so much for purchasing this theme. As I said at the beginning, I'd be glad to help you if you have any questions relating to this theme. No guarantees, but I'll do my best to assist. If you have a more general question relating to the script on Codecanyon, you might consider visiting the forums and asking your question in the "Item Discussion" section.

Hüseyin BABAL

Go To Table of Contents