Skip to content

Commit 488556f

Browse files
authored
Merge pull request #2 from tlscertificate/patch-2
Update JWT.php
2 parents 5f55c61 + db81104 commit 488556f

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/JWT.php

+25
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,24 @@ class JWT
5050
*/
5151
protected $lockSubject = true;
5252

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+
5371
/**
5472
* JWT constructor.
5573
*
@@ -181,6 +199,13 @@ public function getToken()
181199
*/
182200
public function parseToken()
183201
{
202+
if (is_callable(static::$customTokenParser)) {
203+
$token = call_user_func(static::$customTokenParser);
204+
205+
if ($token) {
206+
return $this->setToken($token);
207+
}
208+
}
184209
if (! $token = $this->parser->parseToken()) {
185210
throw new JWTException('The token could not be parsed from the request');
186211
}

0 commit comments

Comments
 (0)