13
13
* @license http://opensource.org/licenses/BSD-3-Clause 3-clause BSD
14
14
* @link https://github.com/firebase/php-jwt
15
15
*/
16
- /**
17
- * JSON Web Token implementation, based on this spec:
18
- * http://tools.ietf.org/html/draft-ietf-oauth-json-web-token-06
19
- *
20
- * @category Authentication
21
- * @package Authentication_JWT
22
- * @author Neuman Vong <[email protected] >
23
- * @author Anant Narayanan <[email protected] >
24
- * @license http://opensource.org/licenses/BSD-3-Clause 3-clause BSD
25
- * @link https://github.com/firebase/php-jwt
26
- */
27
16
class JWT
28
17
{
29
18
static $ methods = array (
@@ -32,13 +21,13 @@ class JWT
32
21
'HS384 ' => array ('hash_hmac ' , 'SHA384 ' ),
33
22
'RS256 ' => array ('openssl ' , 'SHA256 ' ),
34
23
);
35
-
24
+
36
25
/**
37
26
* Decodes a JWT string into a PHP object.
38
27
*
39
- * @param string $jwt The JWT
40
- * @param string|Array|null $key The secret key, or map of keys
41
- * @param bool $verify Don't skip verification process
28
+ * @param string $jwt The JWT
29
+ * @param string|Array|null $key The secret key, or map of keys
30
+ * @param bool $verify Don't skip verification process
42
31
*
43
32
* @return object The JWT's payload as a PHP object
44
33
* @throws UnexpectedValueException Provided JWT was invalid
@@ -71,7 +60,7 @@ public static function decode($jwt, $key = null, $verify = true)
71
60
} else {
72
61
throw new DomainException ('"kid" empty, unable to lookup correct key ' );
73
62
}
74
- }
63
+ }
75
64
if (!JWT ::verify ("$ headb64. $ bodyb64 " , $ sig , $ key , $ header ->alg )) {
76
65
throw new UnexpectedValueException ('Signature verification failed ' );
77
66
}
@@ -98,9 +87,9 @@ public static function decode($jwt, $key = null, $verify = true)
98
87
public static function encode ($ payload , $ key , $ algo = 'HS256 ' , $ keyId = null )
99
88
{
100
89
$ header = array ('typ ' => 'JWT ' , 'alg ' => $ algo );
101
- if ($ keyId !== null ) {
102
- $ header ['kid ' ] = $ keyId ;
103
- }
90
+ if ($ keyId !== null ) {
91
+ $ header ['kid ' ] = $ keyId ;
92
+ }
104
93
$ segments = array ();
105
94
$ segments [] = JWT ::urlsafeB64Encode (JWT ::jsonEncode ($ header ));
106
95
$ segments [] = JWT ::urlsafeB64Encode (JWT ::jsonEncode ($ payload ));
@@ -115,10 +104,10 @@ public static function encode($payload, $key, $algo = 'HS256', $keyId = null)
115
104
/**
116
105
* Sign a string with a given key and algorithm.
117
106
*
118
- * @param string $msg The message to sign
119
- * @param string|resource $key The secret key
120
- * @param string $method The signing algorithm. Supported
121
- * algorithms are 'HS256', 'HS384', 'HS512' and 'RS256'
107
+ * @param string $msg The message to sign
108
+ * @param string|resource $key The secret key
109
+ * @param string $method The signing algorithm. Supported algorithms
110
+ * are 'HS256', 'HS384', 'HS512' and 'RS256'
122
111
*
123
112
* @return string An encrypted message
124
113
* @throws DomainException Unsupported algorithm was specified
@@ -142,7 +131,7 @@ public static function sign($msg, $key, $method = 'HS256')
142
131
}
143
132
}
144
133
}
145
-
134
+
146
135
/**
147
136
* Verify a signature with the mesage, key and method. Not all methods
148
137
* are symmetric, so we must have a separate verify and sign method.
0 commit comments