Skip to content

Commit

Permalink
fixup! fixup! feat: Two Factor API
Browse files Browse the repository at this point in the history
Signed-off-by: SebastianKrupinski <[email protected]>
  • Loading branch information
SebastianKrupinski committed Dec 3, 2024
1 parent 78e280f commit 643480f
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions core/Controller/TwoFactorApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ public function __construct(
/**
* Get two factor authentication provider states
*
* @param list<string> $users collection of system user ids
* @param array<string> $users collection of system user ids
*
* @return DataResponse<Http::STATUS_OK, list{string: list{string: bool}}, array{}>
* @return DataResponse<Http::STATUS_OK, array<string, array<string, bool>>, array{}>
*
* 200: user/provider states
*/
Expand All @@ -54,9 +54,9 @@ public function state(array $users = []): DataResponse {
* Enable two factor authentication providers for specific user
*
* @param string $user system user identifier
* @param list<string> $providers collection of TFA provider ids
* @param array<string> $providers collection of TFA provider ids
*
* @return DataResponse<Http::STATUS_OK|Http::STATUS_NOT_FOUND, list{string: bool}, array{}>
* @return DataResponse<Http::STATUS_OK, array<string, bool>, array{}>|DataResponse<Http::STATUS_NOT_FOUND, null, array{}>
*
* 200: provider states
* 404: user not found
Expand All @@ -66,24 +66,22 @@ public function state(array $users = []): DataResponse {
public function enable(string $user, array $providers = []): DataResponse {
$userObject = $this->userManager->get($user);
if ($userObject !== null) {
if (is_array($providers)) {
foreach ($providers as $providerId) {
$this->tfManager->tryEnableProviderFor($providerId, $userObject);
}
foreach ($providers as $providerId) {
$this->tfManager->tryEnableProviderFor($providerId, $userObject);
}
$state = $this->tfRegistry->getProviderStates($userObject);
return new DataResponse($state);
}
return new DataResponse([], Http::STATUS_NOT_FOUND);
return new DataResponse(null, Http::STATUS_NOT_FOUND);
}

/**
* Disable two factor authentication providers for specific user
*
* @param string $user system user identifier
* @param list<string> $providers collection of TFA provider ids
* @param array<string> $providers collection of TFA provider ids
*
* @return DataResponse<Http::STATUS_OK|Http::STATUS_NOT_FOUND, list{string: bool}, array{}>
* @return DataResponse<Http::STATUS_OK, array<string, bool>, array{}>|DataResponse<Http::STATUS_NOT_FOUND, null, array{}>
*
* 200: provider states
* 404: user not found
Expand All @@ -93,15 +91,13 @@ public function enable(string $user, array $providers = []): DataResponse {
public function disable(string $user, array $providers = []): DataResponse {
$userObject = $this->userManager->get($user);
if ($userObject !== null) {
if (is_array($providers)) {
foreach ($providers as $providerId) {
$this->tfManager->tryDisableProviderFor($providerId, $userObject);
}
foreach ($providers as $providerId) {
$this->tfManager->tryDisableProviderFor($providerId, $userObject);
}
$state = $this->tfRegistry->getProviderStates($userObject);
return new DataResponse($state);
}
return new DataResponse([], Http::STATUS_NOT_FOUND);
return new DataResponse(null, Http::STATUS_NOT_FOUND);
}

}

0 comments on commit 643480f

Please sign in to comment.