-
Notifications
You must be signed in to change notification settings - Fork 54
Expand file tree
/
Copy pathToken.php
More file actions
124 lines (112 loc) · 3.03 KB
/
Token.php
File metadata and controls
124 lines (112 loc) · 3.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<?php
declare(strict_types=1);
namespace ReallySimpleJWT;
/**
* A simple Package for creating JSON Web Tokens that uses HMAC SHA256 to sign
* signatures.
*
* Exposes a simple interface to allow you to create a token that stores a user
* identifier. The Package is set up to allow extension and the use of larger
* payloads. You can use your own encoding if you choose.
*
* For more information on JSON Web Tokens please see https://jwt.io
* along with the RFC https://tools.ietf.org/html/rfc7519
*
* @author Rob Waller <rdwaller1984@gmail.com>
*/
class Token
{
/**
* Create a JSON Web Token that contains a user identifier and a basic
* payload including issued at, expiration and issuer.
*
* @see Tokens::create()
*/
public static function create(string|int $userId, string $secret, int $expiration, string $issuer, array $options = []): string
{
$tokens = new Tokens();
return $tokens->create(
'user_id',
$userId,
$secret,
$expiration,
$issuer,
$options
)->getToken();
}
/**
* @see Tokens::customPayload()
* @param mixed[] $payload
*/
public static function customPayload(array $payload, string $secret): string
{
$tokens = new Tokens();
return $tokens->customPayload($payload, $secret)->getToken();
}
/**
* @see Tokens::validate()
*/
public static function validate(string $token, string $secret): bool
{
$tokens = new Tokens();
return $tokens->validate($token, $secret);
}
/**
* @see Tokens::getHeader()
* @return mixed[]
*/
public static function getHeader(string $token): array
{
$tokens = new Tokens();
return $tokens->getHeader($token);
}
/**
* @see Tokens::getPayload()
* @return mixed[]
*/
public static function getPayload(string $token): array
{
$tokens = new Tokens();
return $tokens->getPayload($token);
}
/**
* @see Tokens::builder()
*/
public static function builder(string $secret): Build
{
$tokens = new Tokens();
return $tokens->builder($secret);
}
/**
* @see Tokens::parser()
*/
public static function parser(string $token): Parse
{
$tokens = new Tokens();
return $tokens->parser($token);
}
/**
* @see Tokens::validator()
*/
public static function validator(string $token, string $secret): Validate
{
$tokens = new Tokens();
return $tokens->validator($token, $secret);
}
/**
* @see Tokens::validateExpiration()
*/
public static function validateExpiration(string $token): bool
{
$tokens = new Tokens();
return $tokens->validateExpiration($token);
}
/**
* @see Tokens::validateNotBefore()
*/
public static function validateNotBefore(string $token): bool
{
$tokens = new Tokens();
return $tokens->validateNotBefore($token);
}
}