Passed
Push — master ( e51815...9c04c0 )
by Radu
02:09
created

AuthenticationToken::decode()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
namespace ParcelValue\Api;
3
4
use Firebase\JWT\JWT;
5
6
final class AuthenticationToken
7
{
8
    const ALGORITHM_HS256 = 'HS256';
9
10
    public static function generate($clientId, $clientKey, $serverKey)
11
    {
12
        return JWT::encode(
13
            [
14
                'sub' => $clientId,
15
                'clientKey' => $clientKey,
16
            ],
17
            $serverKey,
18
            self::ALGORITHM_HS256
19
        );
20
    }
21
22
    public static function decode($string, $serverKey)
23
    {
24
        return JWT::decode(
25
            $string,
26
            $serverKey,
27
            [self::ALGORITHM_HS256]
28
        );
29
    }
30
}
31