Open Journal Systems  3.3.0
AutoBasicAuth.php
1 <?php
2 
4 
7 
13 final class AutoBasicAuth implements Authentication
14 {
20  private $shouldRemoveUserInfo;
21 
25  public function __construct($shouldRremoveUserInfo = true)
26  {
27  $this->shouldRemoveUserInfo = (bool) $shouldRremoveUserInfo;
28  }
29 
33  public function authenticate(RequestInterface $request)
34  {
35  $uri = $request->getUri();
36  $userInfo = $uri->getUserInfo();
37 
38  if (!empty($userInfo)) {
39  if ($this->shouldRemoveUserInfo) {
40  $request = $request->withUri($uri->withUserInfo(''));
41  }
42 
43  $request = $request->withHeader('Authorization', sprintf('Basic %s', base64_encode($userInfo)));
44  }
45 
46  return $request;
47  }
48 }
Http\Message\Authentication
Definition: AutoBasicAuth.php:3
Http\Message\Authentication\AutoBasicAuth\__construct
__construct($shouldRremoveUserInfo=true)
Definition: AutoBasicAuth.php:28
Psr\Http\Message\RequestInterface
Definition: vendor/psr/http-message/src/RequestInterface.php:24
Http\Message\Authentication
Definition: Authentication.php:12
Psr\Http\Message\MessageInterface\withHeader
withHeader($name, $value)
Http\Message\Authentication\AutoBasicAuth\authenticate
authenticate(RequestInterface $request)
Definition: AutoBasicAuth.php:36
Http\Message\Authentication\AutoBasicAuth
Definition: AutoBasicAuth.php:13
Psr\Http\Message\RequestInterface\withUri
withUri(UriInterface $uri, $preserveHost=false)
Psr\Http\Message\RequestInterface\getUri
getUri()