Skip to content

Commit b725930

Browse files
authored
Merge pull request #3 from 200-0K/patch-1
Added Bearer authorization header for the JWTValidateMiddleware
2 parents 4dd8301 + 56a81a7 commit b725930

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/JwtValidateMiddleware.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,15 @@ protected function parseAuthorizationHeader($header)
7474
return $decodedParts[1];
7575
}
7676

77+
if (strpos($header, "Bearer") === 0) {
78+
list($tokenString) = sscanf($header, "Bearer %s");
79+
80+
return $tokenString;
81+
}
82+
7783
// Otherwise we expect the token to be specific directly (not encoded) with the "Token" label
7884
list($tokenString) = sscanf($header, "Token %s");
7985

8086
return $tokenString;
8187
}
82-
}
88+
}

tests/MiddlewareTest.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,12 @@ public function testTokenInAuthorizationHeader()
7373

7474
$request = new \Illuminate\Http\Request();
7575
$request->headers->set('Authorization', 'Basic' . base64_encode('username:foobar'));
76-
7776
$this->assertEquals("foobar", $middleware->findJWT($request));
7877

78+
$request = new \Illuminate\Http\Request();
79+
$request->headers->set('Authorization', 'Bearer baz');
80+
$this->assertEquals("baz", $middleware->findJWT($request));
81+
7982
$request = new \Illuminate\Http\Request();
8083
$request->headers->set('Authorization', 'Token baz');
8184
$this->assertEquals("baz", $middleware->findJWT($request));
@@ -118,4 +121,4 @@ public function testSpecifiedId()
118121
$this->expectExceptionMessage('The token is not identified with the expected ID');
119122
$this->assertEquals("success", $middleware->handle($request, function() { return "success"; }, 'different-id'));
120123
}
121-
}
124+
}

0 commit comments

Comments
 (0)