Skip to content

Commit

Permalink
Build for version v8.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
2fas-com committed Sep 17, 2021
1 parent d6a689a commit d9a3cda
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 396 deletions.
17 changes: 16 additions & 1 deletion Upgrade.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
# Upgrade

### 7.2.0 > 8.0.0

#### requestAuthViaTotpWithMobileSupport
Method has been removed

#### authenticateChannel
Method has been removed

#### updateChannelStatus
Method has been removed

#### IntegrationUser
Field 'push_id' has been removed.
Field 'has_mobile_user' has been removed.

### 6.0.0 > 7.0.0
Main class renamed to `Sdk`.
Php version requirement increased to `>=5.4`.
Expand Down Expand Up @@ -32,4 +47,4 @@ You can do it in Integration edit in [dashboard](https://dashboard.2fas.com).

#### Exceptions
AESCipher, AESGeneratedKey, AESIVGenerator and Cryptographer methods will
throw AesException on openssl failure.
throw AesException on openssl failure.
1 change: 1 addition & 0 deletions composer.lock

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

4 changes: 1 addition & 3 deletions src/Hydrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ public function getIntegrationUserFromResponse(ReadKey $keyStorage, Response $re
$user
->setId($data['id'])
->setExternalId($data['external_id'])
->setPushId($data['push_id'])
->setBackupCodesCount($data['backup_codes_count'])
->setHasMobileUser($data['has_mobile_user'])
->setPhoneNumber($cryptographer->decrypt($data['phone_number']))
->setEmail($cryptographer->decrypt($data['email']))
->setTotpSecret($cryptographer->decrypt($data['totp_secret']));
Expand All @@ -50,4 +48,4 @@ public function getAuthenticationFromResponse(Response $response)
Dates::convertUTCFormatToLocal($data['valid_to'])
);
}
}
}
81 changes: 1 addition & 80 deletions src/IntegrationUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,11 @@ final class IntegrationUser
*/
private $totpSecret;

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

/**
* @var int
*/
private $backupCodesCount;

/**
* @var bool
*/
private $hasMobileUser;

/**
* @return string
*/
Expand Down Expand Up @@ -169,51 +159,6 @@ public function setTotpSecret($totpSecret)
return $this;
}

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

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

/**
* @deprecated
*
* @return null|string
*/
public function getMobileSecret()
{
return $this->getPushId();
}

/**
* @deprecated
*
* @param null|string $mobileSecret
*
* @return IntegrationUser
*/
public function setMobileSecret($mobileSecret)
{
return $this->setPushId($mobileSecret);
}

/**
* @return int
*/
Expand All @@ -237,29 +182,6 @@ public function setBackupCodesCount($backupCodesCount)
return $this;
}

/**
* @return bool
*/
public function hasMobileUser()
{
return $this->hasMobileUser;
}

/**
* @param bool $hasMobileUser
*
* @return $this
*/
public function setHasMobileUser($hasMobileUser)
{
if (!is_bool($hasMobileUser)) {
throw new InvalidArgumentException('Has Mobile User should be a boolean');
}

$this->hasMobileUser = $hasMobileUser;
return $this;
}

/**
* @param Cryptographer $cryptographer
*
Expand All @@ -270,10 +192,9 @@ public function getEncryptedDataAsArray(Cryptographer $cryptographer)
return [
'id' => $this->id,
'external_id' => $this->externalId,
'push_id' => $this->pushId,
'phone_number' => $cryptographer->encrypt($this->getPhoneNumber()->phoneNumber()),
'email' => $cryptographer->encrypt($this->getEmail()),
'totp_secret' => $cryptographer->encrypt($this->getTotpSecret())
];
}
}
}
25 changes: 0 additions & 25 deletions src/MobileSecretGenerator.php

This file was deleted.

99 changes: 1 addition & 98 deletions src/Sdk.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class Sdk
/**
* @var string
*/
const VERSION = '7.2.0';
const VERSION = '8.0.0';

/**
* @var string
Expand Down Expand Up @@ -301,39 +301,6 @@ public function requestAuthViaTotp($secret)
throw $response->getError();
}

/**
* @param string $secret
* @param string $pushId
* @param string $sessionId
* @param string $browserVersion
*
* @return Authentication
*
* @throws AuthorizationException
* @throws InvalidDateException
* @throws ValidationException
* @throws Exception
*/
public function requestAuthViaTotpWithMobileSupport($secret, $pushId, $sessionId, $browserVersion)
{
$response = $this->call(
'POST',
$this->createEndpoint('v3/auth/totp/mobile'),
[
'totp_secret' => (string) $secret,
'push_id' => (string) $pushId,
'session_id' => (string) $sessionId,
'browser_version' => (string) $browserVersion,
]
);

if ($response->matchesHttpCode(HttpCodes::CREATED)) {
return $this->hydrator->getAuthenticationFromResponse($response);
}

throw $response->getError();
}

/**
* Used for validating code entered by user.
*
Expand Down Expand Up @@ -421,70 +388,6 @@ public function checkBackupCode(IntegrationUser $user, array $authentications, $
throw $response->getError();
}

/**
* @param int $integrationId
* @param string $sessionId
* @param string $socketId
*
* @return array
*
* @throws AuthorizationException
* @throws ValidationException
* @throws Exception
*/
public function authenticateChannel($integrationId, $sessionId, $socketId)
{
$channelName = 'private-wp_' . $integrationId . '_' . $sessionId;

$response = $this->call(
'POST',
$this->createEndpoint('v2/integration/authenticate_channel'),
[
'channel_name' => (string) $channelName,
'socket_id' => (string) $socketId
]
);

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

throw $response->getError();
}

/**
* @param string $channelName
* @param int $statusId
* @param string $status
*
* @return array
*
* @throws AuthorizationException
* @throws InvalidArgumentException
* @throws ValidationException
* @throws Exception
*/
public function updateChannelStatus($channelName, $statusId, $status)
{
if (!in_array($status, ChannelStatuses::getAllowedStatuses())) {
throw new InvalidArgumentException('Channel status is not valid.');
}

$response = $this->call(
'POST',
$this->createEndpoint('v2/integration/channel/' . $channelName . '/status/' . $statusId),
[
'status' => (string) $status
]
);

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

throw $response->getError();
}

/**
* Used for getting paginated list of integration users from 2fas.
*
Expand Down
45 changes: 0 additions & 45 deletions tests/Exception/ValidationExceptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,51 +83,6 @@ public function testUniquePhoneNumberValidationRule()
$this->assertEquals([ValidationRules::UNIQUE_PHONE_NUMBER], $exception->getError('code'));
}

public function testPusherSocketIdValidationRule()
{
$errors = ['error' => [
'code' => 9030,
'msg' => [
'code' => [
'validation.pusher_socket_id'
]
]
]];

$exception = $this->getException($errors);
$this->assertEquals([ValidationRules::PUSHER_SOCKET_ID], $exception->getError('code'));
}

public function testPusherChannelNameValidationRule()
{
$errors = ['error' => [
'code' => 9030,
'msg' => [
'code' => [
'validation.pusher_channel_name'
]
]
]];

$exception = $this->getException($errors);
$this->assertEquals([ValidationRules::PUSHER_CHANNEL_NAME], $exception->getError('code'));
}

public function testIntegrationChannelNameValidationRule()
{
$errors = ['error' => [
'code' => 9030,
'msg' => [
'code' => [
'validation.private_integration_channel'
]
]
]];

$exception = $this->getException($errors);
$this->assertEquals([ValidationRules::INTEGRATION_CHANNEL_NAME], $exception->getError('code'));
}

public function testRegexDot()
{
$errors = ['error' => [
Expand Down
18 changes: 0 additions & 18 deletions tests/MobileSecretGeneratorTest.php

This file was deleted.

Loading

0 comments on commit d9a3cda

Please sign in to comment.