diff --git a/src/JwtValidateMiddleware.php b/src/JwtValidateMiddleware.php index c1376e1..4e4ed89 100644 --- a/src/JwtValidateMiddleware.php +++ b/src/JwtValidateMiddleware.php @@ -74,9 +74,15 @@ protected function parseAuthorizationHeader($header) return $decodedParts[1]; } + if (strpos($header, "Bearer") === 0) { + list($tokenString) = sscanf($header, "Bearer %s"); + + return $tokenString; + } + // Otherwise we expect the token to be specific directly (not encoded) with the "Token" label list($tokenString) = sscanf($header, "Token %s"); return $tokenString; } -} \ No newline at end of file +} diff --git a/tests/MiddlewareTest.php b/tests/MiddlewareTest.php index 5f47342..4238cc7 100644 --- a/tests/MiddlewareTest.php +++ b/tests/MiddlewareTest.php @@ -73,9 +73,12 @@ public function testTokenInAuthorizationHeader() $request = new \Illuminate\Http\Request(); $request->headers->set('Authorization', 'Basic' . base64_encode('username:foobar')); - $this->assertEquals("foobar", $middleware->findJWT($request)); + $request = new \Illuminate\Http\Request(); + $request->headers->set('Authorization', 'Bearer baz'); + $this->assertEquals("baz", $middleware->findJWT($request)); + $request = new \Illuminate\Http\Request(); $request->headers->set('Authorization', 'Token baz'); $this->assertEquals("baz", $middleware->findJWT($request)); @@ -118,4 +121,4 @@ public function testSpecifiedId() $this->expectExceptionMessage('The token is not identified with the expected ID'); $this->assertEquals("success", $middleware->handle($request, function() { return "success"; }, 'different-id')); } -} \ No newline at end of file +}