Skip to content

Commit

Permalink
Release Version 11.3.0
Browse files Browse the repository at this point in the history
Release Version 11.3.0
  • Loading branch information
indrasen715 committed Jan 27, 2022
1 parent abc7912 commit 32b9288
Show file tree
Hide file tree
Showing 10 changed files with 131 additions and 22 deletions.
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
> **LoginRadius PHP SDK Change Log** provides information regarding what has changed, more specifically what changes, improvements and bug fix has been made to the SDK. For more details please refer to the [LoginRadius API Documention](https://www.loginradius.com/docs/api/v2/deployment/sdk-libraries/php-library/)


# Version 11.3.0

Release on **January 27, 2022**

## Enhancements

- Added a feature to add ApiKey and ApiSecret directly in LoginRadius manual SOTT generation method.
- Added Licence and Contribution Guideline files.

## Breaking Changes

For developers migrating from v11.2.0, there will be 1 minor breaking change in terms of SDK implementation. In this version, we have added a feature to add ApiKey & ApiSecret directly into the manual SOTT generation method `encrypt()`.


# Version 11.2.0

Release on **September 6, 2021**
Expand Down
41 changes: 41 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Contributing

[PHP SDK](https://github.com/LoginRadius/php-sdk) is [MIT](LICENSE) licensed and accepts contributions via GitHub pull requests. This document outlines some of the conventions on development workflow, commit message formatting, contact points, and other resources to make it easier to get your contribution accepted.

## Getting Started

- Fork the repository on GitHub.
- If you find any bug or Improvement in our existing code-base, please create a pull request as mentioned in Contribution Flow.

## Contribution Flow

This is a rough outline of what a contributor's workflow looks like:

- Create a separate branch from the `dev` branch to base your work.
- Make commits of logical units.
- Make sure your commit messages are in the proper format (see below).
- Push your changes to a topic branch in your fork of the repository.
- Submit a pull request to the original repository.
- **Please ensure that you raise a PR on the `dev` branch instead of `master`.**

#### Commit Messages

Please follow the below format while writing commit messages:

```
title: One line description about your change
<Blank Line>
description: An optional description of your changes.
```

Thanks for your contributions!

## Code of Conduct

### Our Pledge

In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to make participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.

### Our Responsibilities

Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
19 changes: 19 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Copyright (c) 2022 LoginRadius Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
32 changes: 29 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,14 @@ 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.2.0
composer require loginradius/php-sdk:11.3.0
```

Include the following files in your Project Directory

```
require_once "src/LoginRadiusSDK/Utility/Functions.php";
require_once "src/LoginRadiusSDK/Utility/SOTT.php";
require_once "src/LoginRadiusSDK/LoginRadiusException.php";
require_once "src/LoginRadiusSDK/Clients/IHttpClientInterface.php";
require_once "src/LoginRadiusSDK/Clients/DefaultHttpClient.php";
Expand Down Expand Up @@ -107,6 +108,7 @@ define('API_DOMAIN', 'DEFINE_CUSTOM_API_DOMAIN'); // Custom API Domain
Importing/aliasing with the use operator.
```
use \LoginRadiusSDK\Utility\Functions;
use \LoginRadiusSDK\Utility\SOTT;
use \LoginRadiusSDK\LoginRadiusException;
use \LoginRadiusSDK\Clients\IHttpClientInterface;
use \LoginRadiusSDK\Clients\DefaultHttpClient;
Expand All @@ -129,6 +131,7 @@ use \LoginRadiusSDK\CustomerRegistration\Authentication\RiskBasedAuthenticationA
use \LoginRadiusSDK\CustomerRegistration\Authentication\SmartLoginAPI;
use \LoginRadiusSDK\CustomerRegistration\Social\SocialAPI;
use \LoginRadiusSDK\CustomerRegistration\Social\NativeSocialAPI;
```

Create a LoginRadius object :
Expand Down Expand Up @@ -4126,7 +4129,25 @@ API can be used to unsubscribe a WebHook configured on your LoginRadius site.
$result = $webHookAPI->webHookUnsubscribe($payload);
```

### Generate SOTT Manually

SOTT is a secure one-time token that can be created using the API key, API secret, and a timestamp ( start time and end time ). You can manually create a SOTT using the following utility function.

```
$timeDifference =''; // (Optional) The time difference will be used to set the expiration time of SOTT, If you do not pass time difference then the default expiration time of SOTT is 10 minutes.
$getLRserverTime=false; //(Optional) If true it will call LoginRadius Get Server Time Api and fetch basic server information and server time information which is useful when generating an SOTT token.
//The LoginRadius API key and primary API secret can be passed additionally, If the credentials will not be passed then this SOTT function will pick the API credentials from the SDK configuration.
$apiKey=""; //(Optional) LoginRadius Api Key
$apiSecret=""; //(Optional) LoginRadius Api Secret (Only Primary Api Secret is used to generate the SOTT manually)
$sottObj = new SOTT();
$sott = $sottObj->encrypt($timeDifference,$getLRserverTime,$apiKey,$apiSecret);
```



#### Implement Custom HTTP Client
Expand All @@ -4146,16 +4167,21 @@ class CustomHttpClient implements IHttpClient {
}
```
- After that, pass the class name of your custom http client in global variable** $apiClient_class** in your project.
>Note
<br>
>If you manually added LoginRadius SDK then please make sure that customhttpclient.php file included in your project.

>Note: If you manually added LoginRadius SDK then please make sure that customhttpclient.php file included in your project.
```
global $apiClient_class;
$apiClient_class = 'CustomHttpClient';
```

>Now your Custom HTTP client library will be used to handle LoginRadius APIs.





## Demo

Check out the demo and get the full SDK on our [Github](https://github.com/LoginRadius/php-sdk)
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "loginradius/php-sdk",
"description": "LoginRadius PHP SDK v11.2.0",
"description": "LoginRadius PHP SDK v11.3.0",
"keywords": ["loginradius", "phpsdk"],
"type": "library",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion src/LoginRadiusSDK/Clients/DefaultHttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @category : Clients
* @package : DefaultHttpClient
* @author : LoginRadius Team
* @version : 11.2.0
* @version : 11.3.0
* @license : https://opensource.org/licenses/MIT
*/

Expand Down
2 changes: 1 addition & 1 deletion src/LoginRadiusSDK/Clients/IHttpClientInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @category : Clients
* @package : IHttpClientInterface
* @author : LoginRadius Team
* @version : 11.2.0
* @version : 11.3.0
* @license : https://opensource.org/licenses/MIT
*/

Expand Down
2 changes: 1 addition & 1 deletion src/LoginRadiusSDK/LoginRadiusException.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @category : LoginRadiusSDK
* @package : LoginRadiusException
* @author : LoginRadius Team
* @version : 11.2.0
* @version : 11.3.0
* @license : https://opensource.org/licenses/MIT
*/
namespace LoginRadiusSDK;
Expand Down
4 changes: 2 additions & 2 deletions src/LoginRadiusSDK/Utility/Functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @category : Utility
* @package : Functions
* @author : LoginRadius Team
* @version : 11.2.0
* @version : 11.3.0
* @license : https://opensource.org/licenses/MIT
*/

Expand All @@ -23,7 +23,7 @@
class Functions
{

const VERSION = '11.2.0';
const VERSION = '11.3.0';

private static $_apikey;
private static $_apisecret;
Expand Down
33 changes: 20 additions & 13 deletions src/LoginRadiusSDK/Utility/SOTT.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

class SOTT
{

private $_secret;
private $_key;

Expand All @@ -35,30 +34,41 @@ public function __construct()
}

/**
* Encrpyt data.
*
* @param $time
* Generate SOTT Manually.
* @param $timeDifference (optional) The time difference you would like to pass, If you not pass difference then the default value is 10 minutes.
* @param $getLRserverTime (optional) If true it will call LoginRadius Get Server Time Api and fetch basic server information and server time information which is useful when generating an SOTT token.
* @param $apiKey (optional) LoginRadius Api Key.
* @param $apiSecret (optional) LoginRadius Api Secret.
* @return string
*/
public function encrypt($time = '10', $getLRserverTime = false) {
if ($getLRserverTime) {

public function encrypt($timeDifference = '', $getLRserverTime = false, $apiKey = "",$apiSecret = "")
{
$time=!empty($timeDifference)?$timeDifference:'10';

$apiKey=!empty($apiKey)?$apiKey:$this->_key;

$apiSecret=!empty($apiSecret)?$apiSecret:$this->_secret;

if ($getLRserverTime) {
$result = Functions::apiClient("/identity/v2/serverinfo", array("TimeDifference" => $time), array('output_format' => 'json'));
$startTime = isset($result->Sott) ? $result->Sott->StartTime : '';
$startTime = str_replace("-", "/", $startTime);
$endTime = isset($result->Sott) ? $result->Sott->EndTime : '';
$endTime = str_replace("-", "/", $endTime);
$plain_text = $startTime . '#' . $this->_key . "#" . $endTime;
$plain_text = $startTime . '#' . $apiKey . "#" . $endTime;
}

if (!$getLRserverTime || empty($startTime) || empty($endTime)) {
$startTime = 0;
$di = new \DateInterval('PT' . $startTime . 'M');
$di->invert = 1;
$start = new \DateTimeImmutable(gmdate(self::DateFormat));
$plain_text = $start->add($di)->format(self::DateFormat) . '#' . $this->_key . "#" . $start->add(new \DateInterval('PT' . $time . 'M'))->format(self::DateFormat);
$plain_text = $start->add($di)->format(self::DateFormat) . '#' . $apiKey . "#" . $start->add(new \DateInterval('PT' . $time . 'M'))->format(self::DateFormat);
}

$plain_text = mb_convert_encoding($plain_text, 'UTF-8');
$pass_phrase = mb_convert_encoding($this->_secret, 'UTF-8');
$pass_phrase = mb_convert_encoding($apiSecret, 'UTF-8');
$salt = str_pad("", 8, "\0");
$key = hash_pbkdf2('sha1', $pass_phrase, $salt, 10000, self::KEYSIZE / 8, true);

Expand All @@ -73,7 +83,4 @@ public function encrypt($time = '10', $getLRserverTime = false) {
hash_update($ctx, $token);
return $token . '*' . hash_final($ctx);
}

}


0 comments on commit 32b9288

Please sign in to comment.