Passed
Push — master ( 8278f2...2a258c )
by Alexandre
02:55
created

AuthorizationRequestHeaderField   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 17
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A authenticate() 0 9 3
A support() 0 3 1
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;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\VarDumper\VarDumper was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
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
}