|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
namespace Firesphere\GraphQLJWT\Types; |
|
4
|
|
|
|
|
5
|
|
|
use GraphQL\Type\Definition\EnumType; |
|
6
|
|
|
|
|
7
|
|
|
class TokenStatusEnum extends EnumType |
|
8
|
|
|
{ |
|
9
|
|
|
/** |
|
10
|
|
|
* Valid token |
|
11
|
|
|
*/ |
|
12
|
|
|
const STATUS_OK = 'OK'; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Not a valid token |
|
16
|
|
|
*/ |
|
17
|
|
|
const STATUS_INVALID = 'INVALID'; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Expired but can be renewed |
|
21
|
|
|
*/ |
|
22
|
|
|
const STATUS_EXPIRED = 'EXPIRED'; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Expired and cannot be renewed |
|
26
|
|
|
*/ |
|
27
|
|
|
const STATUS_DEAD = 'DEAD'; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Provided user / password were incorrect |
|
31
|
|
|
*/ |
|
32
|
|
|
const STATUS_BAD_LOGIN = 'BAD_LOGIN'; |
|
33
|
|
|
|
|
34
|
|
|
public function __construct() |
|
35
|
|
|
{ |
|
36
|
|
|
$values = [ |
|
37
|
|
|
self::STATUS_OK => [ |
|
38
|
|
|
'value' => self::STATUS_OK, |
|
39
|
|
|
'description' => 'JWT token is valid', |
|
40
|
|
|
], |
|
41
|
|
|
self::STATUS_INVALID => [ |
|
42
|
|
|
'value' => self::STATUS_INVALID, |
|
43
|
|
|
'description' => 'JWT token is not valid', |
|
44
|
|
|
], |
|
45
|
|
|
self::STATUS_EXPIRED => [ |
|
46
|
|
|
'value' => self::STATUS_EXPIRED, |
|
47
|
|
|
'description' => 'JWT token has expired, but can be renewed', |
|
48
|
|
|
], |
|
49
|
|
|
self::STATUS_DEAD => [ |
|
50
|
|
|
'value' => self::STATUS_DEAD, |
|
51
|
|
|
'description' => 'JWT token has expired and cannot be renewed', |
|
52
|
|
|
], |
|
53
|
|
|
self::STATUS_BAD_LOGIN => [ |
|
54
|
|
|
'value' => self::STATUS_BAD_LOGIN, |
|
55
|
|
|
'description' => 'JWT token could not be created due to invalid login credentials', |
|
56
|
|
|
], |
|
57
|
|
|
]; |
|
58
|
|
|
$config = [ |
|
59
|
|
|
'name' => 'TokenStatus', |
|
60
|
|
|
'description' => 'Status of token', |
|
61
|
|
|
'values' => $values, |
|
62
|
|
|
]; |
|
63
|
|
|
|
|
64
|
|
|
parent::__construct($config); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* Safely create a single type creator only |
|
69
|
|
|
* @todo Create a TypeCreator for non-object types |
|
70
|
|
|
* |
|
71
|
|
|
* @return TokenStatusEnum |
|
72
|
|
|
*/ |
|
73
|
|
|
public static function instance(): self |
|
74
|
|
|
{ |
|
75
|
|
|
static $instance = null; |
|
76
|
|
|
if (!$instance) { |
|
77
|
|
|
$instance = new self(); |
|
78
|
|
|
} |
|
79
|
|
|
return $instance; |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
|