1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Created by PhpStorm. |
4
|
|
|
* User: Alexandre |
5
|
|
|
* Date: 27/05/2018 |
6
|
|
|
* Time: 17:53 |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace OAuth2\Roles\ResourceServer\BearerAuthenticationMethods; |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
use Psr\Http\Message\ServerRequestInterface; |
13
|
|
|
use Symfony\Component\VarDumper\VarDumper; |
|
|
|
|
14
|
|
|
|
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Class AuthorizationRequestHeaderField |
18
|
|
|
* @package OAuth2\Roles\ResourceServer\BearerAuthenticationMethods |
19
|
|
|
* |
20
|
|
|
* @see https://tools.ietf.org/html/rfc6750#section-2.1 |
21
|
|
|
* When sending the access token in the "Authorization" request header |
22
|
|
|
* field defined by HTTP/1.1 [RFC2617], the client uses the "Bearer" |
23
|
|
|
* authentication scheme to transmit the access token. |
24
|
|
|
* |
25
|
|
|
* For example: |
26
|
|
|
* |
27
|
|
|
* GET /resource HTTP/1.1 |
28
|
|
|
* Host: server.example.com |
29
|
|
|
* Authorization: Bearer mF_9.B5f-4.1JqM |
30
|
|
|
* |
31
|
|
|
* The syntax of the "Authorization" header field for this scheme |
32
|
|
|
* follows the usage of the Basic scheme defined in Section 2 of |
33
|
|
|
* [RFC2617]. Note that, as with Basic, it does not conform to the |
34
|
|
|
* generic syntax defined in Section 1.2 of [RFC2617] but is compatible |
35
|
|
|
* with the general authentication framework being developed for |
36
|
|
|
* HTTP 1.1 [HTTP-AUTH], although it does not follow the preferred |
37
|
|
|
* practice outlined therein in order to reflect existing deployments. |
38
|
|
|
* The syntax for Bearer credentials is as follows: |
39
|
|
|
* |
40
|
|
|
* b64token = 1*( ALPHA / DIGIT / |
41
|
|
|
* "-" / "." / "_" / "~" / "+" / "/" ) *"=" |
42
|
|
|
* credentials = "Bearer" 1*SP b64token |
43
|
|
|
* |
44
|
|
|
* Clients SHOULD make authenticated requests with a bearer token using |
45
|
|
|
* the "Authorization" request header field with the "Bearer" HTTP |
46
|
|
|
* authorization scheme. Resource servers MUST support this method. |
47
|
|
|
*/ |
48
|
|
|
class AuthorizationRequestHeaderField implements BearerAuthenticationMethodInterface |
49
|
|
|
{ |
50
|
|
|
|
51
|
|
|
public function support(ServerRequestInterface $request): bool |
52
|
|
|
{ |
53
|
|
|
return $request->hasHeader('Authorization'); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function authenticate(ServerRequestInterface $request): ?string |
57
|
|
|
{ |
58
|
|
|
$authorizationHeader = $request->getHeader('Authorization'); |
59
|
|
|
if (!empty($authorizationHeader)) { |
60
|
|
|
if (preg_match('/Bearer\s(\S+)/', $authorizationHeader[0], $matches)) { |
61
|
|
|
return $matches[1]; |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
return null; |
65
|
|
|
} |
66
|
|
|
} |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths