1 | <?php |
||
29 | class Cert extends AbstractAdapter |
||
30 | { |
||
31 | /** |
||
32 | * @var string The `$_SERVER` key which contains the DN |
||
33 | */ |
||
34 | protected $name; |
||
35 | /** |
||
36 | * @var string Regex to match username from DN |
||
37 | */ |
||
38 | protected $regex; |
||
39 | |||
40 | /** |
||
41 | * Creates a new client certificate authentication adapter. |
||
42 | * |
||
43 | * ```php |
||
44 | * // $_SERVER['SSL_CLIENT_S_DN'] = '/O=Acme, Inc/CN=Bob'; |
||
45 | * $adapter = new Cert(); |
||
46 | * $adapter->login($request); // username: "/O=Acme, Inc/CN=Bob" |
||
47 | * |
||
48 | * // $_SERVER['DN'] = '/O=Acme, Inc/CN=Bob'; |
||
49 | * $adapter = new Cert('DN', '#CN=(.+)$#'); |
||
50 | * $adapter->login($request); // username: "Bob" |
||
51 | * ``` |
||
52 | * |
||
53 | * @param string $name The `$_SERVER` key which contains the user cert DN |
||
54 | * @param string $regex A regex to match a username inside the DN (if not |
||
55 | * specified, username is the entire DN). Must have one capture pattern. |
||
56 | */ |
||
57 | 5 | public function __construct(string $name = 'SSL_CLIENT_S_DN', string $regex = null) |
|
62 | |||
63 | /** |
||
64 | * Authenticates the current principal using the provided credentials. |
||
65 | * |
||
66 | * This method will retrieve a value from the SERVER attributes in the |
||
67 | * offset at `$this->name`. |
||
68 | * |
||
69 | * The principal details will include `ip` (remote IP address), `ua` (remote |
||
70 | * User Agent), and `dn` (client SSL distinguished name). |
||
71 | * |
||
72 | * @param \Psr\Http\Message\ServerRequestInterface $request The Server Request message containing credentials |
||
73 | * @return \Caridea\Auth\Principal An authenticated principal |
||
74 | * @throws \Caridea\Auth\Exception\MissingCredentials if no value was found |
||
75 | * in the SERVER field or the provided regular expression doesn't match |
||
76 | */ |
||
77 | 4 | public function login(\Psr\Http\Message\ServerRequestInterface $request): \Caridea\Auth\Principal |
|
93 | } |
||
94 |