Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SDK-3117] Add Attack Protection endpoints #597

Merged
merged 3 commits into from
Feb 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/API/Management.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Auth0\SDK\API;

use Auth0\SDK\API\Management\Actions;
use Auth0\SDK\API\Management\AttackProtection;
use Auth0\SDK\API\Management\Blacklists;
use Auth0\SDK\API\Management\ClientGrants;
use Auth0\SDK\API\Management\Clients;
Expand All @@ -29,6 +30,7 @@
use Auth0\SDK\API\Management\UsersByEmail;
use Auth0\SDK\Configuration\SdkConfiguration;
use Auth0\SDK\Contract\API\Management\ActionsInterface;
use Auth0\SDK\Contract\API\Management\AttackProtectionInterface;
use Auth0\SDK\Contract\API\Management\BlacklistsInterface;
use Auth0\SDK\Contract\API\Management\ClientGrantsInterface;
use Auth0\SDK\Contract\API\Management\ClientsInterface;
Expand Down Expand Up @@ -188,6 +190,11 @@ public function actions(): ActionsInterface
return $this->getClassInstance(Actions::class);
}

public function attackProtection(): AttackProtectionInterface
{
return $this->getClassInstance(AttackProtection::class);
}

public function blacklists(): BlacklistsInterface
{
return $this->getClassInstance(Blacklists::class);
Expand Down
167 changes: 167 additions & 0 deletions src/API/Management/AttackProtection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
<?php

declare(strict_types=1);

namespace Auth0\SDK\API\Management;

use Auth0\SDK\Contract\API\Management\AttackProtectionInterface;
use Auth0\SDK\Utility\Request\RequestOptions;
use Auth0\SDK\Utility\Toolkit;
use Psr\Http\Message\ResponseInterface;

/**
* Class Attack Protection.
* Handles requests to the Attack Protection endpoint of the v2 Management API.
*
* @link https://auth0.com/docs/api/management/v2#!/Attack_Protection
*/
final class AttackProtection extends ManagementEndpoint implements AttackProtectionInterface
{
/**
* Get breached password detection settings.
* Required scope: `read:attack_protection`
*
* @param RequestOptions|null $options Optional. Additional request options to use, such as a field filtering or pagination. (Not all endpoints support these. See @link for supported options.)
*
* @throws \Auth0\SDK\Exception\NetworkException When the API request fails due to a network error.
*
* @link https://auth0.com/docs/api/management/v2#!/Attack_Protection/get_breached_password_detection
*/
public function getBreachedPasswordDetection(
?RequestOptions $options = null
): ResponseInterface {
return $this->getHttpClient()
->method('get')
->addPath('attack-protection', 'breached-password-detection')
->withOptions($options)
->call();
}

/**
* Get the brute force configuration.
* Required scope: `read:attack_protection`
*
* @param RequestOptions|null $options Optional. Additional request options to use, such as a field filtering or pagination. (Not all endpoints support these. See @link for supported options.)
*
* @throws \Auth0\SDK\Exception\NetworkException When the API request fails due to a network error.
*
* @link https://auth0.com/docs/api/management/v2#!/Attack_Protection/get_brute_force_protection
*/
public function getBruteForceProtection(
?RequestOptions $options = null
): ResponseInterface {
return $this->getHttpClient()
->method('get')
->addPath('attack-protection', 'brute-force-protection')
->withOptions($options)
->call();
}

/**
* Get the suspicious IP throttling configuration.
* Required scope: `read:attack_protection`
*
* @param RequestOptions|null $options Optional. Additional request options to use, such as a field filtering or pagination. (Not all endpoints support these. See @link for supported options.)
*
* @throws \Auth0\SDK\Exception\NetworkException When the API request fails due to a network error.
*
* @link https://auth0.com/docs/api/management/v2#!/Attack_Protection/get_suspicious_ip_throttling
*/
public function getSuspiciousIpThrottling(
?RequestOptions $options = null
): ResponseInterface {
return $this->getHttpClient()
->method('get')
->addPath('attack-protection', 'suspicious-ip-throttling')
->withOptions($options)
->call();
}

/**
* Update breached password detection settings.
* Required scope: `update:attack_protection`
*
* @param array<mixed> $body Body content to pass with the API request. See @link for supported options.
* @param RequestOptions|null $options Optional. Additional request options to use, such as a field filtering or pagination. (Not all endpoints support these. See @link for supported options.)
*
* @throws \Auth0\SDK\Exception\ArgumentException When an invalid `body` is provided.
* @throws \Auth0\SDK\Exception\NetworkException When the API request fails due to a network error.
*
* @link https://auth0.com/docs/api/management/v2#!/Attack_Protection/patch_breached_password_detection
*/
public function updateBreachedPasswordDetection(
array $body,
?RequestOptions $options = null
): ResponseInterface {
[$body] = Toolkit::filter([$body])->array()->trim();

Toolkit::assert([
[$body, \Auth0\SDK\Exception\ArgumentException::missing('body')],
])->isArray();

return $this->getHttpClient()
->method('patch')
->addPath('attack-protection', 'breached-password-detection')
->withBody((object) $body)
->withOptions($options)
->call();
}

/**
* Update the brute force configuration.
* Required scope: `update:attack_protection`
*
* @param array<mixed> $body Body content to pass with the API request. See @link for supported options.
* @param RequestOptions|null $options Optional. Additional request options to use, such as a field filtering or pagination. (Not all endpoints support these. See @link for supported options.)
*
* @throws \Auth0\SDK\Exception\NetworkException When the API request fails due to a network error.
*
* @link https://auth0.com/docs/api/management/v2#!/Attack_Protection/patch_brute_force_protection
*/
public function updateBruteForceProtection(
array $body,
?RequestOptions $options = null
): ResponseInterface {
[$body] = Toolkit::filter([$body])->array()->trim();

Toolkit::assert([
[$body, \Auth0\SDK\Exception\ArgumentException::missing('body')],
])->isArray();

return $this->getHttpClient()
->method('patch')
->addPath('attack-protection', 'brute-force-protection')
->withBody((object) $body)
->withOptions($options)
->call();
}

/**
* Update the suspicious IP throttling configuration.
* Required scope: `update:attack_protection`
*
* @param array<mixed> $body Body content to pass with the API request. See @link for supported options.
* @param RequestOptions|null $options Optional. Additional request options to use, such as a field filtering or pagination. (Not all endpoints support these. See @link for supported options.)
*
* @throws \Auth0\SDK\Exception\NetworkException When the API request fails due to a network error.
*
* @link https://auth0.com/docs/api/management/v2#!/Attack_Protection/patch_suspicious_ip_throttling
*/
public function updateSuspiciousIpThrottling(
array $body,
?RequestOptions $options = null
): ResponseInterface {
[$body] = Toolkit::filter([$body])->array()->trim();

Toolkit::assert([
[$body, \Auth0\SDK\Exception\ArgumentException::missing('body')],
])->isArray();

return $this->getHttpClient()
->method('patch')
->addPath('attack-protection', 'suspicious-ip-throttling')
->withBody((object) $body)
->withOptions($options)
->call();
}
}
104 changes: 104 additions & 0 deletions src/Contract/API/Management/AttackProtectionInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<?php

declare(strict_types=1);

namespace Auth0\SDK\Contract\API\Management;

use Auth0\SDK\Utility\Request\RequestOptions;
use Psr\Http\Message\ResponseInterface;

/**
* Interface AttackProtectionInterface
*/
interface AttackProtectionInterface
{
/**
* Get breached password detection settings.
* Required scope: `read:attack_protection`
*
* @param RequestOptions|null $options Optional. Additional request options to use, such as a field filtering or pagination. (Not all endpoints support these. See @link for supported options.)
*
* @throws \Auth0\SDK\Exception\NetworkException When the API request fails due to a network error.
*
* @link https://auth0.com/docs/api/management/v2#!/Attack_Protection/get_breached_password_detection
*/
public function getBreachedPasswordDetection(
?RequestOptions $options = null
): ResponseInterface;

/**
* Get the brute force configuration.
* Required scope: `read:attack_protection`
*
* @param RequestOptions|null $options Optional. Additional request options to use, such as a field filtering or pagination. (Not all endpoints support these. See @link for supported options.)
*
* @throws \Auth0\SDK\Exception\NetworkException When the API request fails due to a network error.
*
* @link https://auth0.com/docs/api/management/v2#!/Attack_Protection/get_brute_force_protection
*/
public function getBruteForceProtection(
?RequestOptions $options = null
): ResponseInterface;

/**
* Get the suspicious IP throttling configuration.
* Required scope: `read:attack_protection`
*
* @param RequestOptions|null $options Optional. Additional request options to use, such as a field filtering or pagination. (Not all endpoints support these. See @link for supported options.)
*
* @throws \Auth0\SDK\Exception\NetworkException When the API request fails due to a network error.
*
* @link https://auth0.com/docs/api/management/v2#!/Attack_Protection/get_suspicious_ip_throttling
*/
public function getSuspiciousIpThrottling(
?RequestOptions $options = null
): ResponseInterface;

/**
* Update breached password detection settings.
* Required scope: `update:attack_protection`
*
* @param array<mixed> $body Body content to pass with the API request. See @link for supported options.
* @param RequestOptions|null $options Optional. Additional request options to use, such as a field filtering or pagination. (Not all endpoints support these. See @link for supported options.)
*
* @throws \Auth0\SDK\Exception\NetworkException When the API request fails due to a network error.
*
* @link https://auth0.com/docs/api/management/v2#!/Attack_Protection/patch_breached_password_detection
*/
public function updateBreachedPasswordDetection(
array $body,
?RequestOptions $options = null
): ResponseInterface;

/**
* Update the brute force configuration.
* Required scope: `update:attack_protection`
*
* @param array<mixed> $body Body content to pass with the API request. See @link for supported options.
* @param RequestOptions|null $options Optional. Additional request options to use, such as a field filtering or pagination. (Not all endpoints support these. See @link for supported options.)
*
* @throws \Auth0\SDK\Exception\NetworkException When the API request fails due to a network error.
*
* @link https://auth0.com/docs/api/management/v2#!/Attack_Protection/patch_brute_force_protection
*/
public function updateBruteForceProtection(
array $body,
?RequestOptions $options = null
): ResponseInterface;

/**
* Update the suspicious IP throttling configuration.
* Required scope: `update:attack_protection`
*
* @param array<mixed> $body Body content to pass with the API request. See @link for supported options.
* @param RequestOptions|null $options Optional. Additional request options to use, such as a field filtering or pagination. (Not all endpoints support these. See @link for supported options.)
*
* @throws \Auth0\SDK\Exception\NetworkException When the API request fails due to a network error.
*
* @link https://auth0.com/docs/api/management/v2#!/Attack_Protection/patch_suspicious_ip_throttling
*/
public function updateSuspiciousIpThrottling(
array $body,
?RequestOptions $options = null
): ResponseInterface;
}
Loading