Skip to content

Commit

Permalink
Minor refactoring for better CQ
Browse files Browse the repository at this point in the history
  • Loading branch information
floriankraemer committed Mar 16, 2024
1 parent 96f80f8 commit e543e4c
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/Authenticator/HttpDigestAuthenticator.php
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,16 @@ protected function getDigestOptions(ServerRequestInterface $request): array
];
}

protected function formatOptions(string $key, mixed $value): string
{
if (is_bool($value)) {
$value = $value ? 'true' : 'false';
return sprintf('%s=%s', $key, $value);
}

return sprintf('%s="%s"', $key, $value);
}

/**
* Generate the login headers
*
Expand All @@ -300,15 +310,12 @@ protected function loginHeaders(ServerRequestInterface $request): array
$options['stale'] = true;
}

$opts = [];
foreach ($options as $k => $v) {
if (is_bool($v)) {
$v = $v ? 'true' : 'false';
$opts[] = sprintf('%s=%s', $k, $v);
}
$formattedOptions = [];
foreach ($options as $key => $value) {
$formattedOptions[] = $this->formatOptions($key, $value);
}

return ['WWW-Authenticate' => 'Digest ' . implode(',', $opts)];
return ['WWW-Authenticate' => 'Digest ' . implode(',', $formattedOptions)];
}

/**
Expand Down

0 comments on commit e543e4c

Please sign in to comment.