Skip to content

Commit

Permalink
Make the bearerToken method case-insensitive (#53627)
Browse files Browse the repository at this point in the history
  • Loading branch information
samtlewis authored Nov 21, 2024
1 parent 62eab15 commit ac3d32e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Illuminate/Http/Concerns/InteractsWithInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function bearerToken()
{
$header = $this->header('Authorization', '');

$position = strrpos($header, 'Bearer ');
$position = strripos($header, 'Bearer ');

if ($position !== false) {
$header = substr($header, $position + 7);
Expand Down
6 changes: 6 additions & 0 deletions tests/Http/HttpRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1074,12 +1074,18 @@ public function testBearerTokenMethod()
$request = Request::create('/', 'GET', [], [], [], ['HTTP_AUTHORIZATION' => 'Bearer fooBearerbar']);
$this->assertSame('fooBearerbar', $request->bearerToken());

$request = Request::create('/', 'GET', [], [], [], ['HTTP_AUTHORIZATION' => 'bearer fooBearerbar']);
$this->assertSame('fooBearerbar', $request->bearerToken());

$request = Request::create('/', 'GET', [], [], [], ['HTTP_AUTHORIZATION' => 'Basic foo, Bearer bar']);
$this->assertSame('bar', $request->bearerToken());

$request = Request::create('/', 'GET', [], [], [], ['HTTP_AUTHORIZATION' => 'Bearer foo,bar']);
$this->assertSame('foo', $request->bearerToken());

$request = Request::create('/', 'GET', [], [], [], ['HTTP_AUTHORIZATION' => 'bearer foo,bar']);
$this->assertSame('foo', $request->bearerToken());

$request = Request::create('/', 'GET', [], [], [], ['HTTP_AUTHORIZATION' => 'foo,bar']);
$this->assertNull($request->bearerToken());
}
Expand Down

0 comments on commit ac3d32e

Please sign in to comment.