BearerAuthMiddleware::authenticate()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 15
ccs 8
cts 8
cp 1
rs 9.4286
cc 2
eloc 7
nc 2
nop 1
crap 2
1
<?php namespace Neomerx\Limoncello\Http\Middleware;
2
3
/**
4
 * Copyright 2015 [email protected] (www.neomerx.com)
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 * http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 */
18
19
use \Symfony\Component\HttpFoundation\Request;
20
21
/**
22
 * @package Neomerx\Limoncello
23
 */
24
class BearerAuthMiddleware extends BaseAuthMiddleware
25
{
26
    /**
27
     * @inheritdoc
28
     */
29
    const AUTHENTICATION_SCHEME = 'Bearer';
30
31
    /**
32
     * @inheritdoc
33
     */
34 1
    protected function authenticate(Request $request)
35
    {
36 1
        $isAuthenticated = false;
37
38
        // 7 is a length of 'Bearer ' in Bearer Auth header
39 1
        $bearerToken = substr($request->headers->get(self::HEADER_AUTHORIZATION), 7);
40
41
        // check user authentication
42 1
        if ($bearerToken !== false) {
43 1
            $authenticateClosure = $this->getAuthenticationClosure();
44 1
            $isAuthenticated     = $authenticateClosure($bearerToken);
45 1
        }
46
47 1
        return $isAuthenticated;
48
    }
49
}
50