The SDK for PHP allows you to add the authentication functions of tuidd to your site simply and quickly.
This page details the features of the module and a quick guide on how to install it.
Installation and configuration
Installation steps
The installation is done through the following steps, for the detail of each one
You can see below in the following sections.
-
Create a tuidd account
As a Service Provider or Wholesale Agent and register your site or application in the tuidd management portal . -
Download the SDK
You can download the latest version of the sdk from here -
Install it
Unzip the ZIP file that contains the SDK in the root directory within your site. It will create a directory called tuidd -
Configure the SDK
You will have to configure the SDK following the steps that are detailed in the section SDK configuration
-
Integrate the Button to your site
Then, you must put the login button following the steps of Integration of the Login button
The configuration is done following these steps :
-
Edit the file tuidd.conf is inside the directory tuidd / conf of the SDK
-
Configure the parameters:
client_id :
It is the ID of the application generated during the registration of your site in the tuidd administration portal. You can find it by entering the management site in the menu My Applications .
Example: 73958620d779-4fdc-bc09-7d521af91278client_secret :
It is the key that was automatically assigned to the application during registration in the management site of tuidd. You can find it by entering the management site in the menu My Applications .
Example: 45759620e745-4adb-b329-5d521af3433home_page_url:
It's the URL where you put the login button. It is used for the SDK to redirect when the user was not authenticated or the session expired.
Example: http://example.comhome_login_url :
It is the URL to which the user will be redirected at the end of the authentication process.
Example: http://example.com/admindefault_language :
Language in which the texts are displayed. The possible values are: English (en), Spanish (es), Portuguà © s (pt) or Francà © s (fr).
Example: es
Integration of the Login button
Step 1:
To get users to access the tuidd services, you must place the tuidd Login button on your page. This allows us to identify the user and make sure that he / she wants to receive the services through our platform.
For this you must include in the source code of the login page, the tuidd library:
index.php
require_once('tuidd/tuidd_lib/tuidd.php'); // my code ... ?> |
Note : In case you have installed the SDK in another site, you should change the path ' tuidd / tuidd_lib / tuidd.php 'by the corresponding.
Step 2:
On the other hand you must include in your page, where you want the Login button of tuidd, the DIV that contains it, to be drawn:
index.php
|
The SDK will automatically take care of painting the button when you load your page.
If you modified the id of the div in the configuration file, remember to also use that in your page, instead of tuidd-sdk in the div tag.
Step 3:
You will have to copy at the beginning of all the pages of your site that require access with a logged in user, the following line of code:
include_once("tuidd/tuidd_lib/client/TuiddClient.php"); TuiddClient::getSingleton()->isLoggedIn(); ?> |
This code means that if the user did not authenticate or the session expired, the system redirects automatically to the page configured in the home_page_url parameter in the configuration file.
Below is a diagram of how the implementation is:
Obtaining user data
To obtain the data of the user who started the session, you can do it in 2 ways:
1- Calling the getUserInfo () function
2- Implementing a callback function (advanced)
Among the user data that you will receive, the most important is the PCR. It univocally identifies the user within your site.
It is returned in the parameter sub of the received object.
Invoking the getUserInfo () function
This function is used to obtain the user's data.
You can use it directly from your page to access the user's information, for example, the first and last name, etc.
The information is returned inside an object user_info .
Example:
include_once(' tuidd/tuidd_lib/client/TuiddClient.php '); // get user information $userInfo = TuiddClient::getSingleton()-> getUserInfo (); // print user information... echo ' echo $userInfo['user_info']['name']." ".$userInfo['user_info']['family_name']; echo ' '; echo ' echo $userInfo['user_info']['sub']; echo ' ';
echo ' echo $userInfo['user_info']['email']; echo ' '; ?> |
To see the rest of the fields available, consult the section User Info of the Authentication REST API .
Implementation of the callback function
This function is invoked by the SDK to process the information received from the authentication process or from any other service.
This function must register it in the advanced configuration file advanced_params.conf that is inside the directory tuidd / includes of the SDK, defining the following parameters:
callback_function : Example: myCallbackFunction
Name of the provider's function that will be executed in the SDK and to which the results of the tuidd services will be passed. The function must receive an object with the data per parameter.
callback_function_file : Example: 'myfuncs / myfunction.php'
Path of the file that contains the callback function, defined in callback_function.
Example:
In this file, a callback function is implemented. The function can be in any part of your code, it is important that you indicate where configuring the configuration file so that the SDK can lift it
myfunction.php
include_once(' tuidd/tuidd_lib/client/TuiddClient.php '); function myCallbackFunction ( $notification ) { // my callback code ... switch $notification['service_type'] { case 'authentication': // get user information... $userInfo= $notification['notification_data']; // print user information... echo ' echo $userInfo['user_info']['name']." ".$userInfo['user_info']['family_name']; echo ' ';
echo ' echo $userInfo['user_info']['sub']; echo ' ';
echo ' echo $userInfo['user_info']['email']; echo ' '; break; } } ?> |
Security
The SDK comes with security configurations for Apache. If you use this WEB server, you should not make any additional configuration to the one of your site.
In case of using another Web server, you must configure in it, that you DO NOT have access to the following SDK directories:
tuidd/ +---conf/ +---docs/ +---includes/ +---lib/ +---language/ +---libs/
|
Advanced configuration
The configuration is done following these steps :
1. Edit the file advanced_params.conf that is inside the directory tuidd / includes of the SDK
2. Configure the parameters:
callback_function : Example: myCallbackFuncion
The name of the provider's function that will be executed in the SDK and to which the authentication result data will be passed. The function must receive an object with the data per parameter.
callback_function_file : Example: 'myfuncs / myfunction.php'
Absolute path of the file that contains the callback function, defined in callback_function.
scope : Example: openid profile
List of ASCII strings "case-sensitive"? with values of the scope of the authentication requirement, of the OAuth 2.0 standard. According to the standard it must contain the at least the value openid.
Other possible values are: profile, email, address, phone, offline_access, tuidd_notification, tuidd_advertising, tuidd_survey, tuidd_payment, tuidd_coupon.
By default, the SDK requests all the user.
For more information about the values of scope see the Authentication section of the Authentication REST API .
security_level : Example: 3 2
Are the security level values (LOAs) required by the application, in order of preference, according to ISO / IEC 29115 Clause 6 "1, 2, 3, 4" representing the LOW, MEDIUM, HIGH and VERY HIGH levels respectively. Keep in mind that tuidd currently only supports the values 2 and 3. The value finally used is returned in the field acr in the authentication.
The default value is 2.
For more information see the Authentication section of the Authentication REST API.
tuidd_sdk_path : Example: / my_plugins / tuidd /
Indicates in which directory relative to the root of the site the SDK has been installed.
The default value is 'tuidd /', referring to a location in the root of the site.
redirect_uri : Example: http: //domain/dir/tuidd/index.php
Absolute URI to which it is redirected once the user is authorized.
It must match the one registered in the tuidd administration site, in the RETURN URL parameter of the creation of the application.
container_div : Example: tuidd-sdk
Id of the referring to the wrapper of the tuidd button. By default, the value is tuidd-sdk.
In order to use the SDK, you need your site to use the following modules and versions:
-PHP 5+
-JQuery 1.8+
Version |
v2.0.0 |
Date |
31/01/2020 |
Description |
SDK complement for PHP |
Compatibility |
- |
Discharge |
Historical changes
v2.0.0 |
31/01/2020 |
|
v1.0.0 |
01/26/2018 |
|