File tree 1 file changed +25
-0
lines changed
1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -50,6 +50,24 @@ class JWT
50
50
*/
51
51
protected $ lockSubject = true ;
52
52
53
+ /**
54
+ * Custom your token parser here.
55
+ *
56
+ * @var Callable
57
+ */
58
+ protected static $ customTokenParser = null ;
59
+
60
+ /**
61
+ * Custom token parser
62
+ *
63
+ * @param callable $callback
64
+ * @return void
65
+ */
66
+ public static function customTokenParser (Callable $ callback )
67
+ {
68
+ static ::$ customTokenParser = $ callback ;
69
+ }
70
+
53
71
/**
54
72
* JWT constructor.
55
73
*
@@ -181,6 +199,13 @@ public function getToken()
181
199
*/
182
200
public function parseToken ()
183
201
{
202
+ if (is_callable (static ::$ customTokenParser )) {
203
+ $ token = call_user_func (static ::$ customTokenParser );
204
+
205
+ if ($ token ) {
206
+ return $ this ->setToken ($ token );
207
+ }
208
+ }
184
209
if (! $ token = $ this ->parser ->parseToken ()) {
185
210
throw new JWTException ('The token could not be parsed from the request ' );
186
211
}
You can’t perform that action at this time.
0 commit comments