|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Created by PhpStorm. |
|
4
|
|
|
* User: Alexandre |
|
5
|
|
|
* Date: 09/06/2018 |
|
6
|
|
|
* Time: 18:47 |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace OAuth2\Roles\ResourceServer\BearerAuthenticationMethods; |
|
10
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
use Psr\Http\Message\ServerRequestInterface; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Class URIQueryParameter |
|
16
|
|
|
* @package OAuth2\Roles\ResourceServer\BearerAuthenticationMethods |
|
17
|
|
|
* |
|
18
|
|
|
* @see https://tools.ietf.org/html/rfc6750#section-2.3 |
|
19
|
|
|
* When sending the access token in the HTTP request URI, the client |
|
20
|
|
|
* adds the access token to the request URI query component as defined |
|
21
|
|
|
* by "Uniform Resource Identifier (URI): Generic Syntax" [RFC3986], |
|
22
|
|
|
* using the "access_token" parameter. |
|
23
|
|
|
* |
|
24
|
|
|
* For example, the client makes the following HTTP request using |
|
25
|
|
|
* transport-layer security: |
|
26
|
|
|
* |
|
27
|
|
|
* GET /resource?access_token=mF_9.B5f-4.1JqM HTTP/1.1 |
|
28
|
|
|
* Host: server.example.com |
|
29
|
|
|
* |
|
30
|
|
|
* The HTTP request URI query can include other request-specific |
|
31
|
|
|
* parameters, in which case the "access_token" parameter MUST be |
|
32
|
|
|
* properly separated from the request-specific parameters using "&" |
|
33
|
|
|
* character(s) (ASCII code 38). |
|
34
|
|
|
* |
|
35
|
|
|
* For example: |
|
36
|
|
|
* |
|
37
|
|
|
* https://server.example.com/resource?access_token=mF_9.B5f-4.1JqM&p=q |
|
38
|
|
|
* |
|
39
|
|
|
* Clients using the URI Query Parameter method SHOULD also send a |
|
40
|
|
|
* Cache-Control header containing the "no-store" option. Server |
|
41
|
|
|
* success (2XX status) responses to these requests SHOULD contain a |
|
42
|
|
|
* Cache-Control header with the "private" option. |
|
43
|
|
|
* |
|
44
|
|
|
* Because of the security weaknesses associated with the URI method |
|
45
|
|
|
* (see Section 5), including the high likelihood that the URL |
|
46
|
|
|
* containing the access token will be logged, it SHOULD NOT be used |
|
47
|
|
|
* unless it is impossible to transport the access token in the |
|
48
|
|
|
* "Authorization" request header field or the HTTP request entity-body. |
|
49
|
|
|
* Resource servers MAY support this method. |
|
50
|
|
|
* |
|
51
|
|
|
* This method is included to document current use; its use is not |
|
52
|
|
|
* recommended, due to its security deficiencies (see Section 5) and |
|
53
|
|
|
* also because it uses a reserved query parameter name, which is |
|
54
|
|
|
* counter to URI namespace best practices, per "Architecture of the |
|
55
|
|
|
* World Wide Web, Volume One" [W3C.REC-webarch-20041215]. |
|
56
|
|
|
*/ |
|
57
|
|
|
class URIQueryParameter implements BearerAuthenticationMethodInterface |
|
58
|
|
|
{ |
|
59
|
|
|
|
|
60
|
|
|
public function support(ServerRequestInterface $request): bool |
|
61
|
|
|
{ |
|
62
|
|
|
return isset($request->getQueryParams()['access_token']); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
public function authenticate(ServerRequestInterface $request): ?string |
|
66
|
|
|
{ |
|
67
|
|
|
return $request->getQueryParams()['access_token'] ?? null; |
|
68
|
|
|
} |
|
69
|
|
|
} |