Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Authentication.php
Go to the documentation of this file.
1 <?php
6 namespace Magento\Framework\HTTP;
7 
12 {
18  protected $request;
19 
25  protected $response;
26 
31  public function __construct(
32  \Magento\Framework\App\RequestInterface $httpRequest,
33  \Magento\Framework\App\ResponseInterface $httpResponse
34  ) {
35  $this->request = $httpRequest;
36  $this->response = $httpResponse;
37  }
38 
46  public function getCredentials()
47  {
48  $server = $this->request->getServerValue();
49  $user = '';
50  $pass = '';
51 
52  if (empty($server['HTTP_AUTHORIZATION'])) {
53  foreach ($server as $k => $v) {
54  if (substr($k, -18) === 'HTTP_AUTHORIZATION' && !empty($v)) {
55  $server['HTTP_AUTHORIZATION'] = $v;
56  break;
57  }
58  }
59  }
60 
61  if (isset($server['PHP_AUTH_USER']) && isset($server['PHP_AUTH_PW'])) {
62  $user = $server['PHP_AUTH_USER'];
63  $pass = $server['PHP_AUTH_PW'];
64  } elseif (!empty($server['HTTP_AUTHORIZATION'])) {
69  $auth = $server['HTTP_AUTHORIZATION'];
70  list($user, $pass) = explode(':', base64_decode(substr($auth, strpos($auth, " ") + 1)));
71  } elseif (!empty($server['Authorization'])) {
72  $auth = $server['Authorization'];
73  list($user, $pass) = explode(':', base64_decode(substr($auth, strpos($auth, " ") + 1)));
74  }
75 
76  return [$user, $pass];
77  }
78 
85  public function setAuthenticationFailed($realm)
86  {
87  $this->response->setStatusHeader(401, '1.1', 'Unauthorized');
88  $this->response->setHeader(
89  'WWW-Authenticate',
90  'Basic realm="' . $realm . '"'
91  )->setBody(
92  '<h1>401 Unauthorized</h1>'
93  );
94  }
95 }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
__construct(\Magento\Framework\App\RequestInterface $httpRequest, \Magento\Framework\App\ResponseInterface $httpResponse)
$user
Definition: dummy_user.php:13