1: | <?php |
2: | |
3: | /* |
4: | * Library to use PortBilling events with PSR-14 event dispatch |
5: | */ |
6: | |
7: | namespace Porta\Psr14Event\Auth; |
8: | |
9: | use Porta\Psr14Event\EventException; |
10: | |
11: | /** |
12: | * Class to perform custom authentification |
13: | * |
14: | * Create an instance of class with password and username and then check Event |
15: | * for credentials: |
16: | * ``` |
17: | * (new AuthBasic('customType','customValue'))->authentificate($event) |
18: | * ``` |
19: | * |
20: | * @api |
21: | * @package Auth |
22: | */ |
23: | class AuthCustom extends Auth |
24: | { |
25: | |
26: | protected string $customeType; |
27: | protected string $customValue; |
28: | |
29: | /** |
30: | * Sets custom auth type and value |
31: | * |
32: | * @param string $customeType |
33: | * @param string $customValue |
34: | * @api |
35: | */ |
36: | public function __construct(string $customeType, string $customValue) |
37: | { |
38: | $this->customeType = $customeType; |
39: | $this->customValue = $customValue; |
40: | } |
41: | |
42: | /** |
43: | * @internal |
44: | * @return void |
45: | * @throws EventException |
46: | */ |
47: | protected function check(): void |
48: | { |
49: | if (($this->authType != $this->customeType) || |
50: | ($this->authValue != $this->customValue)) { |
51: | throw new EventException("Custom auth failed", 401); |
52: | } |
53: | } |
54: | } |
55: |