Completed
Pull Request — master (#1035)
by Matt
03:17
created

S256Verifier   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 0
dl 0
loc 28
rs 10
c 0
b 0
f 0
ccs 6
cts 6
cp 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getMethod() 0 4 1
A verifyCodeChallenge() 0 7 1
1
<?php
2
/**
3
 * @author      Lukáš Unger <[email protected]>
4
 * @copyright   Copyright (c) Lukáš Unger
5
 * @license     http://mit-license.org/
6
 *
7
 * @link        https://github.com/thephpleague/oauth2-server
8
 */
9
10
namespace League\OAuth2\Server\CodeChallengeVerifiers;
11
12
class S256Verifier implements CodeChallengeVerifierInterface
13
{
14
    /**
15
     * Return code challenge method.
16
     *
17
     * @return string
18
     */
19 45
    public function getMethod()
20
    {
21 45
        return 'S256';
22
    }
23
24
    /**
25
     * Verify the code challenge.
26
     *
27
     * @param string $codeVerifier
28
     * @param string $codeChallenge
29
     *
30
     * @return bool
31
     */
32 3
    public function verifyCodeChallenge($codeVerifier, $codeChallenge)
33
    {
34 3
        return hash_equals(
35 3
            strtr(rtrim(base64_encode(hash('sha256', $codeVerifier, true)), '='), '+/', '-_'),
36 3
            $codeChallenge
37
        );
38
    }
39
}
40