Skip to content

Commit

Permalink
feat(auth): require email and password for MFA authentication
Browse files Browse the repository at this point in the history
- Updated AuthenticateMfaRequest to include 'email' and 'password' in required fields.
- Modified AuthenticateMfaRequestBody to change email and password properties from nullable to non-nullable.
- Adjusted the constructor to accept 'email' and 'password' parameters.
- Simplified methods to get properties directly without null checks.
  • Loading branch information
mittwald-machine committed Sep 30, 2024
1 parent 563c4d3 commit aad3e17
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ class AuthenticateMfaRequest
],
'required' => [
'multiFactorCode',
'email',
'password',
],
'type' => 'object',
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,16 @@ class AuthenticateMfaRequestBody
],
'required' => [
'multiFactorCode',
'email',
'password',
],
'type' => 'object',
];

/**
* The email of the user.
*/
private ?string $email = null;
private string $email;

/**
* The second factor - otp code or recovery code.
Expand All @@ -51,26 +53,28 @@ class AuthenticateMfaRequestBody
/**
* The password of the user.
*/
private ?string $password = null;
private string $password;

public function __construct(string $multiFactorCode)
public function __construct(string $email, string $multiFactorCode, string $password)
{
$this->email = $email;
$this->multiFactorCode = $multiFactorCode;
$this->password = $password;
}

public function getEmail(): ?string
public function getEmail(): string
{
return $this->email ?? null;
return $this->email;
}

public function getMultiFactorCode(): string
{
return $this->multiFactorCode;
}

public function getPassword(): ?string
public function getPassword(): string
{
return $this->password ?? null;
return $this->password;
}

public function withEmail(string $email): self
Expand All @@ -87,14 +91,6 @@ public function withEmail(string $email): self
return $clone;
}

public function withoutEmail(): self
{
$clone = clone $this;
unset($clone->email);

return $clone;
}

public function withMultiFactorCode(string $multiFactorCode): self
{
$validator = new Validator();
Expand Down Expand Up @@ -123,14 +119,6 @@ public function withPassword(string $password): self
return $clone;
}

public function withoutPassword(): self
{
$clone = clone $this;
unset($clone->password);

return $clone;
}

/**
* Builds a new instance from an input array
*
Expand All @@ -146,19 +134,12 @@ public static function buildFromInput(array|object $input, bool $validate = true
static::validateInput($input);
}

$email = null;
if (isset($input->{'email'})) {
$email = $input->{'email'};
}
$email = $input->{'email'};
$multiFactorCode = $input->{'multiFactorCode'};
$password = null;
if (isset($input->{'password'})) {
$password = $input->{'password'};
}
$password = $input->{'password'};

$obj = new self($email, $multiFactorCode, $password);

$obj = new self($multiFactorCode);
$obj->email = $email;
$obj->password = $password;
return $obj;
}

Expand All @@ -170,13 +151,9 @@ public static function buildFromInput(array|object $input, bool $validate = true
public function toJson(): array
{
$output = [];
if (isset($this->email)) {
$output['email'] = $this->email;
}
$output['email'] = $this->email;
$output['multiFactorCode'] = $this->multiFactorCode;
if (isset($this->password)) {
$output['password'] = $this->password;
}
$output['password'] = $this->password;

return $output;
}
Expand Down

0 comments on commit aad3e17

Please sign in to comment.