Skip to content

payasweene/oxd-php-library

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

oxd-php-library

oxd-php-library is a client library for the Gluu oxd Server. For information about oxd, visit http://oxd.gluu.org

Pre Requisite

Required

Optional

OXD-TO-HTTP Server is required if you want to access OXD server over HTTP.

Attention
Applications will not be working if your hosts does not have https://.

Installation

Source

oxd-php-library source is available on Github:

Composer: oxd-php-api

This is the preferred method. See the composer website for installation instructions if you do not already have it installed.

To install oxd-php-api via Composer, execute the following command in your project root:

$ composer install `composer require "gluufederation/oxd-php-api": "3.0.1"`

Note: OpenID Connect requires https. This library will not work if your website uses http only.

Configuration

The oxd-php-library configuration file is located in 'oxd-rp-settings.json'. The values here are used during registration. For a full list of supported oxd configuration parameters, see the oxd documentation Below is a typical configuration data set for registration:

{
   "op_host":"<GLUU Server url>",
   "oxd_host":"<OXD server host IP>",
   "oxd_host_port":8099,
   "authorization_redirect_uri":"[https://client.example.com/welcome]",
   "post_logout_redirect_uri":"[https://client.example.com/welcome]",
   "scope":[
      "openid",
      "profile",
      "uma_protection",
      "uma_authorization"
   ],
   "application_type":"web",
   "response_types":[
      "code"
   ],
   "grant_types":[
      "authorization_code"
   ],
   "acr_values":[
      ""
   ]
}
                        
  • oxd_host_port - oxd port or socket

OXD-To-HTTP Configuration

The oxd-php-library configuration file is located in 'oxdHttpConfig.php'. The values here are used during the usage of all GLUU protocols.For a full list of supported protocols, see the oxd protocol documentation.

return [
    'host' => '<OXD-TO-HTTP Host>',
    'get_authorization_url' => "get-authorization-url",
    'update_site_registration' => "update-site",
    'get_tokens_by_code' => "get-tokens-by-code",
    'get_user_info' => "get-user-info",
    'register_site' => "register-site",
    'get_logout_uri' => "logout"
];
                        

Sample code

Register.php (OXD-TO-HTTP)

Example

	require_once './utils.php';
    require_once './oxdlibrary/Register_site.php';
    $config = include('./oxdlibrary/oxdHttpConfig.php');

    if(!checkOxdId())
    {
        setRedirectUrl($_REQUEST['redirectUrl']);
        try{
            $register_site = new Register_site($config);
            $register_site->setRequestOpHost(Oxd_RP_config::$op_host);
            $register_site->setRequestAcrValues(Oxd_RP_config::$acr_values);
            $register_site->setRequestAuthorizationRedirectUri(Oxd_RP_config::$authorization_redirect_uri);
            $register_site->setRequestPostLogoutRedirectUri(Oxd_RP_config::$post_logout_redirect_uri);
            $register_site->setRequestGrantTypes(Oxd_RP_config::$grant_types);
            $register_site->setRequestResponseTypes(Oxd_RP_config::$response_types);
            $register_site->setRequestScope(Oxd_RP_config::$scope);
            $register_site->request();
            setOxdId($register_site->getResponseOxdId());
            $data["status"] = "ok";
            echo json_encode($data);
        }
        catch(Exception $e){
            echo "{\"error\":\"".$e->getMessage()."\"}";
        }
    }
    else {
        $data["status"] = "done";
        $rdpSettings = getOxdRpSettings();
        $data["redirectUrl"] = $rdpSettings->authorization_redirect_uri;
        echo json_encode($data);
   }

                        

Register.php (SOCKET)

Example

	require_once './utils.php';
    require_once './oxdlibrary/Register_site.php';
    $config = include('./oxdlibrary/oxdHttpConfig.php');

    if(!checkOxdId())
    {
        setRedirectUrl($_REQUEST['redirectUrl']);
        try{
            $register_site = new Register_site();
            $register_site = new Register_site($config);
            $register_site->setRequestOpHost(Oxd_RP_config::$op_host);
            $register_site->setRequestAcrValues(Oxd_RP_config::$acr_values);
            $register_site->setRequestAuthorizationRedirectUri(Oxd_RP_config::$authorization_redirect_uri);
            $register_site->setRequestPostLogoutRedirectUri(Oxd_RP_config::$post_logout_redirect_uri);
            $register_site->setRequestGrantTypes(Oxd_RP_config::$grant_types);
            $register_site->setRequestResponseTypes(Oxd_RP_config::$response_types);
            $register_site->setRequestScope(Oxd_RP_config::$scope);
            $register_site->request();
            setOxdId($register_site->getResponseOxdId());
            $data["status"] = "ok";
            echo json_encode($data);
        }
        catch(Exception $e){
            echo "{\"error\":\"".$e->getMessage()."\"}";
        }
    }
    else {
        $data["status"] = "done";
        $rdpSettings = getOxdRpSettings();
        $data["redirectUrl"] = $rdpSettings->authorization_redirect_uri;
        echo json_encode($data);
   }

                        

Update.php (OXD-TO-HTTP)

Example

	require_once './utils.php';
    require_once './oxdlibrary/Update_site_registration.php';
    $config = include('./oxdlibrary/oxdHttpConfig.php');
    
    if(checkOxdId())
    {
        $oxdId = getOxdId();
        try{
            $update_site_registration = new Update_site_registration($config);
            $update_site_registration->setRequestAcrValues(Oxd_RP_config::$acr_values);
            $update_site_registration->setRequestOxdId($oxdId);
            $update_site_registration->setRequestAuthorizationRedirectUri(Oxd_RP_config::$authorization_redirect_uri);
            $update_site_registration->setRequestPostLogoutRedirectUri($_POST['postLogoutRedirectUrl']);
            $update_site_registration->setRequestContacts([$_POST['oxdEmail']]);
            $update_site_registration->setRequestGrantTypes(Oxd_RP_config::$grant_types);
            $update_site_registration->setRequestResponseTypes(Oxd_RP_config::$response_types);
            $update_site_registration->setRequestScope(Oxd_RP_config::$scope);
            $update_site_registration->request();
            echo "{\"status\":\"ok\"}";
        }
        catch(Exception $e){
            echo "{\"error\":\"".$e->getMessage()."\"}";
        }
    }
    else {
        echo "{\"error\":\"Please register your site first\"";
    }

                        

Update.php (SOCKET)

Example

	require_once './utils.php';
    require_once './oxdlibrary/Update_site_registration.php';
    $config = include('./oxdlibrary/oxdHttpConfig.php');
    
    if(checkOxdId())
    {
        $oxdId = getOxdId();
        try{
			$update_site_registration = new Update_site_registration();
            $update_site_registration->setRequestAcrValues(Oxd_RP_config::$acr_values);
            $update_site_registration->setRequestOxdId($oxdId);
            $update_site_registration->setRequestAuthorizationRedirectUri(Oxd_RP_config::$authorization_redirect_uri);
            $update_site_registration->setRequestPostLogoutRedirectUri($_POST['postLogoutRedirectUrl']);
            $update_site_registration->setRequestContacts([$_POST['oxdEmail']]);
            $update_site_registration->setRequestGrantTypes(Oxd_RP_config::$grant_types);
            $update_site_registration->setRequestResponseTypes(Oxd_RP_config::$response_types);
            $update_site_registration->setRequestScope(Oxd_RP_config::$scope);
            $update_site_registration->request();
            echo "{\"status\":\"ok\"}";
        }
        catch(Exception $e){
            echo "{\"error\":\"".$e->getMessage()."\"}";
        }
    }
    else {
        echo "{\"error\":\"Please register your site first\"";
    }

                        

GetAuthorizationUrl.php (OXD-TO-HTTP)

Example

	require_once './utils.php';
    require_once './oxdlibrary/Get_authorization_url.php';
    $config = include('./oxdlibrary/oxdHttpConfig.php');
    
    if(checkOxdId())
    {
        $oxdId = getOxdId();
        try{
            $get_authorization_url = new Get_authorization_url($config);
            $get_authorization_url->setRequestOxdId($oxdId);
            $get_authorization_url->setRequestScope(Oxd_RP_config::$scope);
            $get_authorization_url->setRequestAcrValues(Oxd_RP_config::$acr_values);
            $get_authorization_url->request();
            echo "{\"authorizationUrl\":\"".$get_authorization_url->getResponseAuthorizationUrl()."\"}";
        }
        catch(Exception $e){
            echo $e->getMessage();
        }
    }
    else {
        echo "Please register your site first";
    }
                        

GetAuthorizationUrl.php (SOCKET)

Example

	require_once './utils.php';
    require_once './oxdlibrary/Get_authorization_url.php';
    $config = include('./oxdlibrary/oxdHttpConfig.php');
    
    if(checkOxdId())
    {
        $oxdId = getOxdId();
        try{
            $get_authorization_url = new Get_authorization_url();
            $get_authorization_url->setRequestOxdId($oxdId);
            $get_authorization_url->setRequestScope(Oxd_RP_config::$scope);
            $get_authorization_url->setRequestAcrValues(Oxd_RP_config::$acr_values);
            $get_authorization_url->request();
            echo "{\"authorizationUrl\":\"".$get_authorization_url->getResponseAuthorizationUrl()."\"}";
        }
        catch(Exception $e){
            echo $e->getMessage();
        }
    }
    else {
        echo "Please register your site first";
    }
                        

GetTokens.php (OXD-TO-HTTP)

Example

	require_once './utils.php';
    require_once './oxdlibrary/Get_tokens_by_code.php';
    $config = include('./oxdlibrary/oxdHttpConfig.php');
    
    if(checkOxdId())
    {
        $oxdId = getOxdId();
        try{
            $get_tokens_by_code = new Get_tokens_by_code($config);
            $get_tokens_by_code->setRequestOxdId($oxdId);
            $get_tokens_by_code->setRequestCode($_REQUEST['authCode']);
            $get_tokens_by_code->setRequestState($_REQUEST['authState']);
            $get_tokens_by_code->request();
            $data['accessToken'] = $get_tokens_by_code->getResponseAccessToken();
            $data['refreshToken'] = $get_tokens_by_code->getResponseRefreshToken();
            $data['idToken'] = $get_tokens_by_code->getResponseIdToken();
            $data['idTokenClaims'] = $get_tokens_by_code->getResponseIdTokenClaims();
            echo json_encode($data);
        }
        catch(Exception $e){
            echo $e->getMessage();
        }
    }
    else {
        echo "Please register your site first";
    }

GetTokens.php (SOCKET)

Example

	require_once './utils.php';
    require_once './oxdlibrary/Get_tokens_by_code.php';
    $config = include('./oxdlibrary/oxdHttpConfig.php');
    
    if(checkOxdId())
    {
        $oxdId = getOxdId();
        try{
			$get_tokens_by_code = new Get_tokens_by_code();
            $get_tokens_by_code->setRequestOxdId($oxdId);
            $get_tokens_by_code->setRequestCode($_REQUEST['authCode']);
            $get_tokens_by_code->setRequestState($_REQUEST['authState']);
            $get_tokens_by_code->request();
            $data['accessToken'] = $get_tokens_by_code->getResponseAccessToken();
            $data['refreshToken'] = $get_tokens_by_code->getResponseRefreshToken();
            $data['idToken'] = $get_tokens_by_code->getResponseIdToken();
            $data['idTokenClaims'] = $get_tokens_by_code->getResponseIdTokenClaims();
            echo json_encode($data);
        }
        catch(Exception $e){
            echo $e->getMessage();
        }
    }
    else {
        echo "Please register your site first";
    }

GetUserInfo.php (OXD-TO-HTTP)

Example

	require_once './utils.php';
    require_once './oxdlibrary/Get_user_info.php';
    $config = include('./oxdlibrary/oxdHttpConfig.php');
    
    if(checkOxdId())
    {
        $oxdId = getOxdId();
        try{
            $get_user_info = new Get_user_info($config);
            $get_user_info->setRequestOxdId($oxdId);
            $get_user_info->setRequestAccessToken($_REQUEST['accessToken']);
            $get_user_info->request();
            $data = $get_user_info->getResponseClaims();
            $response['userEmail'] = $data->email[0];
            $response['userName'] = $data->name[0];
            echo json_encode($response);
        }
        catch(Exception $e){
            echo $e->getMessage();
        }
    }
    else {
        echo "Please register your site first";
    }
                        

GetUserInfo.php (SOCKET)

Example

	require_once './utils.php';
    require_once './oxdlibrary/Get_user_info.php';
    $config = include('./oxdlibrary/oxdHttpConfig.php');
    
    if(checkOxdId())
    {
        $oxdId = getOxdId();
        try{
			$get_user_info = new Get_user_info();
            $get_user_info->setRequestOxdId($oxdId);
            $get_user_info->setRequestAccessToken($_REQUEST['accessToken']);
            $get_user_info->request();
            $data = $get_user_info->getResponseClaims();
            $response['userEmail'] = $data->email[0];
            $response['userName'] = $data->name[0];
            echo json_encode($response);
        }
        catch(Exception $e){
            echo $e->getMessage();
        }
    }
    else {
        echo "Please register your site first";
    }
                        

GetLogoutUri.php (OXD-TO-HTTP)

Example

	require_once './utils.php';
    require_once './oxdlibrary/Logout.php';
    $config = include('./oxdlibrary/oxdHttpConfig.php');
    
    if(checkOxdId())
    {
        $oxdId = getOxdId();
        try{
            $get_logout_uri = new Logout($config);
            $get_logout_uri->setRequestOxdId($oxdId);
            $get_logout_uri->request();
            $data["logoutUri"] = $get_logout_uri->getResponseObject()->data->uri;
            echo json_encode($data);
        }
        catch(Exception $e){
            echo $e->getMessage();
        }
    }
    else {
        echo "Please register your site first";
    }
                        

GetLogoutUri.php (SOCKET)

Example

	require_once './utils.php';
    require_once './oxdlibrary/Logout.php';
    $config = include('./oxdlibrary/oxdHttpConfig.php');
    
    if(checkOxdId())
    {
        $oxdId = getOxdId();
        try{
			$get_logout_uri = new Logout();
            $get_logout_uri->setRequestOxdId($oxdId);
            $get_logout_uri->request();
            $data["logoutUri"] = $get_logout_uri->getResponseObject()->data->uri;
            echo json_encode($data);
        }
        catch(Exception $e){
            echo $e->getMessage();
        }
    }
    else {
        echo "Please register your site first";
    }
                        

Packages

No packages published

Languages

  • PHP 76.0%
  • CSS 24.0%