| 1 |
<?php |
| 2 |
|
| 3 |
namespace Intervention\HttpAuth\Token; |
| 4 |
|
| 5 |
use Intervention\HttpAuth\Key; |
| 6 |
|
| 7 |
class HttpAuthentification extends NullToken |
| 8 |
{ |
| 9 |
/** |
| 10 |
* Parsed authentification value |
| 11 |
* |
| 12 |
* @var string |
| 13 |
*/ |
| 14 |
protected $value; |
| 15 |
|
| 16 |
/** |
| 17 |
* Transform current instance to key object |
| 18 |
* |
| 19 |
* @return Key |
| 20 |
*/ |
| 21 |
public function toKey(): Key |
| 22 |
{ |
| 23 |
list($username, $password) = explode(':', base64_decode(substr($this->value, 6))); |
| 24 |
|
| 25 |
$key = new Key(); |
| 26 |
$key->setProperty('username', $username); |
| 27 |
$key->setProperty('password', $password); |
| 28 |
|
| 29 |
return $key; |
| 30 |
} |
| 31 |
|
| 32 |
/** |
| 33 |
* Parse environment variables and store value in object |
| 34 |
* |
| 35 |
* @return bool "true" if value was found or "false" |
| 36 |
*/ |
| 37 |
protected function parse(): bool |
| 38 |
{ |
| 39 |
$value = $this->getArrayValue($_SERVER, 'HTTP_AUTHENTICATION'); |
| 40 |
if (strtolower(substr($value, 0, 5)) === 'basic') { |
| 41 |
$this->value = $value; |
| 42 |
|
| 43 |
return true; |
| 44 |
} |
| 45 |
|
| 46 |
return false; |
| 47 |
} |
| 48 |
} |
| 49 |
|