From bfac35e68493e60c496a26962a966dd4ea54d47e Mon Sep 17 00:00:00 2001 From: LoginRadius Date: Wed, 28 Sep 2022 15:14:09 +0530 Subject: [PATCH] Release Version 11.4.2 --- CHANGELOG.md | 8 ++++++++ README.md | 5 ++++- composer.json | 2 +- demo/ajax_handler/config.php | 6 ++++++ .../Clients/DefaultHttpClient.php | 19 ++++++++++++++++--- src/LoginRadiusSDK/Utility/Functions.php | 6 +++++- 6 files changed, 40 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b14220c..c1ebdc9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,14 @@ +# Version 11.4.2 + +Release on **September 28, 2022** + +## Enhancements + +- Added Referer Header Feature + # Version 11.4.1 diff --git a/README.md b/README.md index 57c0a34..1bb52c8 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ curl -sS https://getcomposer.org/installer | php Next, run the Composer command to install the latest stable version of library: ``` -composer require loginradius/php-sdk:11.4.1 +composer require loginradius/php-sdk:11.4.2 ``` Include the following files in your Project Directory @@ -95,6 +95,9 @@ define('USER', 'PROXY_USER'); // Replace PROXY_USER with your proxy server usern define('PASSWORD', 'PROXY_PASSWORD'); // Replace PROXY_PASSWORD with your proxy server password. define('API_DOMAIN', 'DEFINE_CUSTOM_API_DOMAIN'); // Custom API Domain +define('REFERER', 'DEFINE_REFERER'); // The referer header is used to determine the registration source from which the user has created the account and is synced in the RegistrationSource field for the user profile. When initializing the SDK, you can optionally specify Referer Header. + + ``` >Replace 'LOGINRADIUS_SITE_NAME_HERE', 'LOGINRADIUS_API_KEY_HERE' and 'LOGINRADIUS_API_SECRET_HERE' in the above code with your LoginRadius Site Name, LoginRadius API Key, and Secret.This information can be found in your LoginRadius account as described [here](https://www.loginradius.com/docs/api/v2/admin-console/platform-security/api-key-and-secret). diff --git a/composer.json b/composer.json index fe15b4d..c64a98f 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "loginradius/php-sdk", - "description": "LoginRadius PHP SDK v11.4.1", + "description": "LoginRadius PHP SDK v11.4.2", "keywords": ["loginradius", "phpsdk"], "type": "library", "license": "MIT", diff --git a/demo/ajax_handler/config.php b/demo/ajax_handler/config.php index 517d1b5..8d3ba63 100644 --- a/demo/ajax_handler/config.php +++ b/demo/ajax_handler/config.php @@ -10,6 +10,12 @@ //otherwise no need to define these option in configuration. // define('API_DOMAIN', 'https://api.loginradius.com'); + + + +// The referer header is used to determine the registration source from which the user has created the account and is synced in the RegistrationSource field for the user profile. When initializing the SDK, you can optionally specify Referer Header. +//define('REFERER', 'DEFINE_REFERER'); + require_once "../../src/LoginRadiusSDK/Utility/Functions.php"; require_once "../../src/LoginRadiusSDK/LoginRadiusException.php"; require_once "../../src/LoginRadiusSDK/Clients/IHttpClientInterface.php"; diff --git a/src/LoginRadiusSDK/Clients/DefaultHttpClient.php b/src/LoginRadiusSDK/Clients/DefaultHttpClient.php index d39b307..cc9a21f 100644 --- a/src/LoginRadiusSDK/Clients/DefaultHttpClient.php +++ b/src/LoginRadiusSDK/Clients/DefaultHttpClient.php @@ -47,6 +47,11 @@ public function request($path, $queryArray = array(), $options = array()) if (defined('ORIGIN_IP') && ORIGIN_IP != "") { $options['ORIGIN_IP'] = ORIGIN_IP; } + if (defined('REFERER') && REFERER != "") { + if ($path == "/identity/v2/auth/register" || $path == "/identity/v2/auth/register/captcha") { + $options['Referer'] = REFERER; + } + } if (defined('API_REQUEST_SIGNING') && API_REQUEST_SIGNING != "") { $options['api_request_signing'] = API_REQUEST_SIGNING; } else { @@ -124,6 +129,7 @@ private function curlApiMethod($requestUrl, $options = array()) $expiryTime = isset($options['X-Request-Expires']) ? trim($options['X-Request-Expires']) : ''; $digest = isset($options['digest']) ? trim($options['digest']) : ''; $originIp = isset($options['ORIGIN_IP']) ? trim($options['ORIGIN_IP']) : ''; + $referer = isset($options['Referer']) ? trim($options['Referer']) : ''; $curlHandle = curl_init(); curl_setopt($curlHandle, CURLOPT_URL, $requestUrl); @@ -149,6 +155,9 @@ private function curlApiMethod($requestUrl, $options = array()) } if($originIp!=''){ $optionsArray[]='X-Origin-IP: '. $originIp; + } + if ($referer != '') { + $optionsArray[] = 'Referer: ' . $referer; } curl_setopt($curlHandle, CURLOPT_HTTPHEADER, $optionsArray); if(defined('PROTOCOL') && PROTOCOL != "" && defined('HOST') && HOST != "" && defined('PORT') && PORT != "" && defined('USER') && USER != "" && defined('PASSWORD') && PASSWORD != "") { @@ -197,7 +206,8 @@ private function fsockopenApiMethod($requestUrl, $options = array()) $expiryTime = isset($options['X-Request-Expires']) ? trim($options['X-Request-Expires']) : ''; $digest = isset($options['digest']) ? trim($options['digest']) : ''; $originIp = isset($options['ORIGIN_IP']) ? trim($options['ORIGIN_IP']) : ''; - + $referer = isset($options['Referer']) ? trim($options['Referer']) : ''; + $optionsArray = array('http' => array( 'method' => strtoupper($method), @@ -235,7 +245,10 @@ private function fsockopenApiMethod($requestUrl, $options = array()) if($originIp != ''){ $optionsArray['http']['header'] .= "\r\n" . 'X-Origin-IP: ' . $originIp; } - + if ($referer != '') { + $optionsArray['http']['header'] .= "\r\n" . 'Referer: ' . $referer; + } + $context = stream_context_create($optionsArray); $jsonResponse['response'] = file_get_contents($requestUrl, false, $context); $parseHeaders = Functions::parseHeaders($http_response_header); @@ -249,4 +262,4 @@ private function fsockopenApiMethod($requestUrl, $options = array()) } return $jsonResponse; } -} +} \ No newline at end of file diff --git a/src/LoginRadiusSDK/Utility/Functions.php b/src/LoginRadiusSDK/Utility/Functions.php index a410eae..a777816 100644 --- a/src/LoginRadiusSDK/Utility/Functions.php +++ b/src/LoginRadiusSDK/Utility/Functions.php @@ -22,7 +22,7 @@ class Functions { - const VERSION = '11.4.1'; + const VERSION = '11.4.2'; private static $_apikey; private static $_apisecret; @@ -51,6 +51,10 @@ public function __construct($customizeOptions = array()) if (!defined('API_CONFIG_DOMAIN')) { define('API_CONFIG_DOMAIN', 'https://config.lrcontent.com'); } + + if (!defined('REFERER')) { + define('REFERER', 'API'); + } self::$_options = array_merge(self::$_options, $customizeOptions); }