Tutorial: Authentication with Social Media

In this tutorial we will see how to create a control to perform authentication only with Social Network. (No need to create all, it only takes one)


1. Create an application of control type.


2. In the application menu, go to “Authentications”.


You must have the configuration data of each social network. Follow the tutorials available in our database:

3. After having all the data for configuration, go to the menu of the application “Development> PHP methods” and click “New Method”.


4. Create three methods for your social network: – fb_return – go_return – tw_return

5. For each method, you must add a few lines of code.

5.1. For the method “fb_return” write:

if(!empty([facebook_error_code]))
{
sc_error_message(urlencode([facebook_error_msg]));
}
else
{
[auth_type] = "facebook";
[user_id] = [facebook_user];
[user_photo] = [facebook_photo];
[user_name] = [facebook_name];
sc_redir("NAME_OF_YOUR_APPLICATION");
}

5.2. For the method “go_return” write:

[auth_type] = "google";
[user_id] = [google_user];
[user_photo] = [google_photo];
[user_name] = [google_name];
sc_redir("NAME_OF_YOUR_APPLICATION");

5.3. For the method “tw_return” write:

[auth_type] = "twitter";
[user_id] = [twitter_user];
[user_photo] = [twitter_photo];
[user_name] = [twitter_name];
sc_redir("NAME_OF_YOUR_APPLICATION");

The codes above are to receive user data.

6. Return to the application menu “Authentications” and select the “Method Return” of each of the social networks based on methods previously created.



7. In the application menu go to “Fields” and click “New Field”.


8. In the “Quantity” enter 4.

9. Create the fields: tip, photo, id and name, all of the type label.


10. In the application menu, go to “Events> onLoad” and enter the following code to update the user information based on the social network.


if((isset([auth_type])) && (!empty([auth_type]))){
switch ([auth_type]){ 
case "twitter":
{tip} = {lang_auth_logged}."Twitter!";  break;
case "google":
{tip} = {lang_auth_logged}."Google+!";  break;
case "facebook":
{tip} = {lang_auth_logged}."Facebook!"; break;

}
{photo} = "<img src='".[user_photo]."' />";
{id} = [user_id];
{name} = [user_name];

}else{ 

{photo} = "";
{id} = "";
{name} = ""; 
}

11. In the application menu, go to “Events> onValidateSuccess” and enter the following code to clear the information whenever performed a new login.


sc_reset_global([auth_type], [facebook_user], [facebook_photo], [facebook_name], [twitter_user], [twitter_photo], [twitter_name], [google_user], [google_photo], [google_name]);

12. In the application menu, go to “Toolbar”.


13. In the properties of “Top toolbar” add the three social networks.


14. Publish the application on the server that was the “Apps” of social networks were configured. (You must publish because does not work locally)

Tutorials in the same category

Email confirmation

In this tutorial we will see how to create a registration confirmation form for scheduling courses. ...

How to Send an e-mail with attachment

On this tutorial, Send an e-mail with attachment. 1. Create a new control form application 2...

How to send an E-mail using the macro sc_mail_send

On this tutorial, Send an email using the macro sc_mail_send. 1. Create a new control form applicat...

Comment this post