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

89 - Allow string url for verify action #98

Open
wants to merge 1 commit into
base: 10.next-cake5
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ public function proceed(ServerRequestInterface $request, ResultInterface $result
* Generates 2fa url, if enable.
*
* @param string $type Processor type.
* @return array|null
* @return array|string|null
*/
public function getUrlByType(string $type): ?array
public function getUrlByType(string $type): array|string|null
{
if ($type == $this->getType()) {
return Configure::read('OneTimePasswordAuthenticator.verifyAction');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ public function proceed(ServerRequestInterface $request, ResultInterface $result
* Generates 2fa url, if enable.
*
* @param string $type Processor type.
* @return array|null
* @return array|string|null
*/
public function getUrlByType(string $type): ?array
public function getUrlByType(string $type): array|string|null
{
if ($type == $this->getType()) {
return Configure::read('Webauthn2fa.startAction');
Expand Down
4 changes: 2 additions & 2 deletions src/Authentication/TwoFactorProcessorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function proceed(ServerRequestInterface $request, ResultInterface $result
* Generates 2fa url, if enable.
*
* @param string $type Processor type.
* @return array|null
* @return array|string|null
*/
public function getUrlByType(string $type): ?array;
public function getUrlByType(string $type): array|string|null;
}
12 changes: 9 additions & 3 deletions src/Middleware/TwoFactorMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,15 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
$session->write(CookieAuthenticator::SESSION_DATA_KEY, [
'remember_me' => $data['remember_me'] ?? null,
]);
$url = array_merge($url, [
'?' => $request->getQueryParams(),
]);
$params = $request->getQueryParams();
if (is_array($url)) {
$url = array_merge($url, [
'?' => $params,
]);
} else {
$url .= '?' . implode('&', array_map(fn ($k, $v) => "$k=$v", array_keys($params), array_values($params)));
}

$url = Router::url($url);

return (new Response())
Expand Down
Loading