Skip to content

Commit

Permalink
Build for version v6.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
2fas-com committed Oct 23, 2018
1 parent 331fc66 commit e5d6e6c
Show file tree
Hide file tree
Showing 17 changed files with 533 additions and 710 deletions.
2 changes: 1 addition & 1 deletion TwoFAS/Api/Exception/ValidationException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace TwoFAS\Api\Exception;

use TwoFAS\Api\ValidationRules;
use TwoFAS\ValidationRules\ValidationExceptionInterface;
use TwoFAS\ValidationRules\ValidationRules;

/**
* Validation Exceptions may contain multiple keys and rules.
Expand Down
43 changes: 7 additions & 36 deletions TwoFAS/Api/IntegrationUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@ final class IntegrationUser
*/
private $externalId;

/**
* @var null|string
*/
private $activeMethod;

/**
* @var null|string
*/
Expand Down Expand Up @@ -105,29 +100,6 @@ public function setExternalId($externalId)
return $this;
}

/**
* @return null|string
*/
public function getActiveMethod()
{
return $this->activeMethod;
}

/**
* @param null|string $activeMethod
*
* @return IntegrationUser
*/
public function setActiveMethod($activeMethod)
{
if (null === $activeMethod || '' === $activeMethod) {
$this->activeMethod = null;
return $this;
}
$this->activeMethod = (string) $activeMethod;
return $this;
}

/**
* @return FormattedNumber
*/
Expand Down Expand Up @@ -273,14 +245,13 @@ public function setHasMobileUser($hasMobileUser)
*/
public function getEncryptedDataAsArray(Cryptographer $cryptographer)
{
$data = array();
$data['id'] = $this->id;
$data['external_id'] = $this->externalId;
$data['active_method'] = $this->activeMethod;
$data['mobile_secret'] = $this->mobileSecret;
$data['phone_number'] = $cryptographer->encrypt($this->getPhoneNumber()->phoneNumber());
$data['email'] = $cryptographer->encrypt($this->getEmail());
$data['totp_secret'] = $cryptographer->encrypt($this->getTotpSecret());
$data = array();
$data['id'] = $this->id;
$data['external_id'] = $this->externalId;
$data['mobile_secret'] = $this->mobileSecret;
$data['phone_number'] = $cryptographer->encrypt($this->getPhoneNumber()->phoneNumber());
$data['email'] = $cryptographer->encrypt($this->getEmail());
$data['totp_secret'] = $cryptographer->encrypt($this->getTotpSecret());

return $data;
}
Expand Down
8 changes: 5 additions & 3 deletions TwoFAS/Api/MobileSecretGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

namespace TwoFAS\Api;

use TwoFAS\Encryption\Random\RandomGenerator;
use TwoFAS\Encryption\Random\NonCryptographicalRandomIntGenerator;
use TwoFAS\Encryption\Random\RandomStringGenerator;

/**
* This class helps you generate mobile secret.
Expand All @@ -16,8 +17,9 @@ class MobileSecretGenerator
*/
public static function generate()
{
$generator = new RandomGenerator();
$intGenerator = new NonCryptographicalRandomIntGenerator();
$stringGenerator = new RandomStringGenerator($intGenerator);

return $generator->alphaNum(32)->toLower()->__toString();
return $stringGenerator->alphaNum(32)->toLower()->__toString();
}
}
80 changes: 3 additions & 77 deletions TwoFAS/Api/TwoFAS.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use TwoFAS\Api\Exception\ChannelNotActiveException;
use TwoFAS\Api\Exception\CountryIsBlockedException;
use TwoFAS\Api\Exception\Exception;
use TwoFAS\Api\Exception\IntegrationUserHasNoActiveMethodException;
use TwoFAS\Api\Exception\IntegrationUserNotFoundException;
use TwoFAS\Api\Exception\InvalidDateException;
use TwoFAS\Api\Exception\InvalidNumberException;
Expand All @@ -36,7 +35,7 @@ class TwoFAS
/**
* @var string
*/
const VERSION = '5.0.6';
const VERSION = '6.0.0';

/**
* @var string
Expand Down Expand Up @@ -140,58 +139,6 @@ public function formatNumber($phoneNumber)
throw $response->getError();
}

/**
* Used for requesting authentication of integration user.
* This method merges all authentication methods.
* Store authentication id for later use.
*
* @param ReadKey $keyStorage
* @param string $userId
*
* @return Authentication
*
* @throws AuthenticationLimitationException
* @throws AuthorizationException
* @throws ChannelNotActiveException
* @throws CountryIsBlockedException
* @throws IntegrationUserHasNoActiveMethodException
* @throws IntegrationUserNotFoundException
* @throws InvalidDateException
* @throws InvalidNumberException
* @throws NumberLimitationException
* @throws PaymentException
* @throws SmsToLandlineException
* @throws ValidationException
* @throws Exception
*/
public function requestAuth(ReadKey $keyStorage, $userId)
{
$user = $this->getIntegrationUser($keyStorage, $userId);
$method = $user->getActiveMethod();

if (Methods::SMS === $method) {
return $this->requestAuthViaSms($user->getPhoneNumber()->phoneNumber());
}

if (Methods::CALL === $method) {
return $this->requestAuthViaCall($user->getPhoneNumber()->phoneNumber());
}

if (Methods::EMAIL === $method) {
return $this->requestAuthViaEmail($user->getEmail());
}

if (Methods::TOTP === $method) {
return $this->requestAuthViaTotp($user->getTotpSecret());
}

if (null === $method) {
throw new IntegrationUserHasNoActiveMethodException('No active method');
}

throw new Exception('Unsupported method');
}

/**
* Used for requesting authentication on user via SMS.
* Store authentication id for later use.
Expand Down Expand Up @@ -724,28 +671,6 @@ public function regenerateBackupCodes(IntegrationUser $user)
throw $response->getError();
}

/**
* Used for displaying Statistics.
*
* @return Statistics
*
* @throws AuthorizationException
* @throws Exception
*/
public function getStatistics()
{
$response = $this->call(
'GET',
$this->createEndpoint('/users_statistic')
);

if ($response->matchesHttpCode(HttpCodes::OK)) {
return new Statistics($response->getData());
}

throw $response->getError();
}

/**
* @param ReadKey $keyStorage
* @param Response $response
Expand All @@ -760,7 +685,6 @@ private function hydrateIntegrationUserFromResponse(ReadKey $keyStorage, Respons
$user
->setId($data['id'])
->setExternalId($data['external_id'])
->setActiveMethod($data['active_method'])
->setMobileSecret($data['mobile_secret'])
->setBackupCodesCount($data['backup_codes_count'])
->setHasMobileUser($data['has_mobile_user'])
Expand Down Expand Up @@ -839,6 +763,8 @@ private function createEndpoint($suffix)
* @param array $data
*
* @return Response
*
* @throws Exception
*/
private function call($method, $endpoint, array $data = array())
{
Expand Down
11 changes: 11 additions & 0 deletions Upgrade.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Upgrade

### 5.0.0 > 6.0.0

#### ValidationRules
Deprecated class has been removed, use `TwoFAS\ValidationRules\ValidationRules` instead.

#### IntegrationUser
Field 'active_method' has been removed.

#### RequestAuth
Method has been removed, use specific type of authentication instead.

### 4.0.6 > 5.0.0

#### Storage
Expand Down
11 changes: 7 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "twofas/sdk",
"description": "SDK for 2fas.com API",
"type": "library",
"description": "SDK for 2fas.com API",
"license": "MIT",
"authors": [
{
Expand All @@ -16,11 +16,12 @@
"require": {
"php": ">=5.3.3",
"ext-curl": "*",
"ext-json": "*",
"endroid/qr-code": "~1.6.0",
"twofas/encryption": "~3.0",
"twofas/encryption": "~4.0",
"twofas/validation-rules": "~1.0"
},
"require-dev" : {
"require-dev": {
"phpunit/phpunit": "4.5.0",
"squizlabs/php_codesniffer": "^2.2",
"wimg/php-compatibility": "^8.0"
Expand All @@ -31,6 +32,8 @@
}
},
"autoload-dev": {
"classmap": ["tests/"]
"classmap": [
"tests/"
]
}
}
15 changes: 8 additions & 7 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions tests/AuthenticationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ class AuthenticationTest extends PHPUnit_Framework_TestCase
*/
private $time20Ago;

public function __construct($name = null, array $data = array(), $dataName = '')
protected function setUp()
{
parent::__construct($name, $data, $dataName);
parent::setUp();

$this->setLocalTimezone();

Expand Down Expand Up @@ -73,7 +73,7 @@ public function testAuthenticationAfter20MinutesIsInvalid()

private function getTimeInLocalTimezone($timestamp)
{
return new DateTime("@$timestamp", $this->getLocalTimezone());
return new DateTime("@{$timestamp}", $this->getLocalTimezone());
}

/**
Expand Down
4 changes: 4 additions & 0 deletions tests/CurlClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@
namespace TwoFAS\Api\tests;

use PHPUnit_Framework_TestCase;
use ReflectionException;
use ReflectionMethod;
use TwoFAS\Api\HttpClient\CurlClient;

class CurlClientTest extends PHPUnit_Framework_TestCase
{
/**
* @throws ReflectionException
*/
public function testMapHeaders()
{
$sourceHeaders = array(
Expand Down
10 changes: 8 additions & 2 deletions tests/DatesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,26 @@ class DatesTest extends PHPUnit_Framework_TestCase
*/
private $dateFormat = 'Y-m-d H:i:s';

public function __construct($name = null, array $data = array(), $dataName = '')
protected function setUp()
{
parent::__construct($name, $data, $dataName);
parent::setUp();

$this->setLocalTimezone();
}

/**
* @throws \TwoFAS\Api\Exception\InvalidDateException
*/
public function testCallingDatesWithDifferentFormat()
{
$this->setExpectedException('TwoFAS\Api\Exception\InvalidDateException');

Dates::convertUTCFormatToLocal('19:20:34 2001/09/13');
}

/**
* @throws \TwoFAS\Api\Exception\InvalidDateException
*/
public function testDateFromApiWillShowAsLocalDate()
{
$utcDate = '2017-01-18 14:21:51';
Expand Down
Loading

0 comments on commit e5d6e6c

Please sign in to comment.