PHP Server Side SDK

Summary

In this topic you will get an overview how to use the PHP SDK to connect to The Identity Hub.

Contents

  • Installing the SDK
  • Configuring the PHP SDK
  • Initialization in application
  • Authenticate
  • Getting information on the current user
  • Getting information on the current user roles
  • Getting information on the current user's friends
  • Getting information on the current user's accounts

Installing the SDK

  • Navigate to the detail page of the App.

  • Open the Web Applications PHP section by clicking on the arrow.

  • Click the SDK link to download the preconfigured SDK for the App.

  • To install just extract the zip file and add the SDK folder (theidentityhub) to directory of the project.

Configuring the PHP SDK

The config.php file will contain the configured values for the specific The Identity Hub App:

$this->config->baseUrl = "https://www.theidentityhub.com/[Tenant URL segment]";
$this->config->clientId = "[Client Id]";
$this->config->client_secret = "[ClientSecret]";
$this->config->redirectUri = "https://[Path to SDK]/theidentityhub/callback.php";
$this->config->signOutUri = "https://[Path to SDK]/theidentityhub/signout.php";
$this->config->signOutRedirectUri = "[Your redirect link]";
        
Fill out the signOutUri (replace [Path to SDK] with you web url) and the signOutRedirectUri (page url to redirect to after signout).

A demo application is available on the App detail page in the “Web Applications PHP” section.

Initialization in application

To initialize the SDK in the application file where you want to use it, at the top of the file there should be:

require_once '[Your path to SDK]/theidentityhub.php';
session_start();
$ih = new TheIdentityHub;
            
The last line will initialize object which will pick up configuration and later when the user is logged on it will load main identity data.

Authenticate

The method getSignInURL() returns the link which will redirect to The Identity Hub's Authentication page:

$ih-> getSignInURL();
        
and also there is a method to get the sign out link:

$ih-> getSignOutURL();
        
which you can use anywhere in your application.

Getting information on the current user

The information about current user is loaded automatically with initialization and stored at main object property identity which is stdClass object as specified in The Identity Hub API

Getting information on the current user roles

The information about current user roles is accessible with method:

$ih->getRoles();
            
This method will fill up main object property $ih->roles with the array of object with property "name" in which will be stored role name.

Getting information on the current user's friends

The information about current user's friends is accessible with method:

$ih->getFriends($offset = 0, $limit = 500)
            
where offset is page number (default 0) and limit is number of records per page (default 500). This method will fill up main object property $ih->friends with the array of object with friend data as specified in The Identity Hub API

Getting information on the current user's accounts

The information about current user's accounts is accessible with method:

$ih->getAccounts()
            
This method will fill up main object property $ih->accounts with the array of object with accounts data as specified in The Identity Hub API

Api

TheIdentityHub

Provides methods to query an identity's profile.

Name Description
IdentityService Initializes a new instance of the TheIdentityHub class
Name Description Remarks
identity Main object property with identity information.
roles Main object property with role information.
accounts Main object property with identity accounts information.
friends Main object property with friends information.
Name Description
getSignInURL() The method getSignInURL() returns the link which will redirect to The Identity Hub's Authentication page.
getSignOutURL() The method getSignOutURL() returns the link to perform sign out which you can use anywhere in the application.
getProfile() This method will fill up main object property $ih->identity object with profile data as specified in The Identity Hub API https://www.theidentityhub.com/hub/Documentation/#GET-tenant-api-identity-v1.
getRoles() This method will fill up main object property $ih->roles with the array of object with property "name" in which will be stored role name.
getFriends() This method will fill up main object property $ih->friends with the array of object with friends data as specified in The Identity Hub API https://www.theidentityhub.com/hub/Documentation/#GET-tenant-api-identity-v1-friends_offset_limit.
getAccounts() This method will fill up main object property $ih->accounts with the array of object with accounts data as specified in The Identity Hub API https://www.theidentityhub.com/hub/Documentation/#GET-tenant-api-identity-v1-accounts.