Skip to content

Commit f7a19cd

Browse files
authored
Merge pull request #1403 from thephpleague/case-insensitive-basic-auth
Make Basic Auth Case Insensitive
2 parents ca511c1 + a53f144 commit f7a19cd

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
55
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
66

77
## [Unreleased]
8+
### Fixed
9+
- Basic authorization is now case insensitive (PR #1403)
810

911
## [9.0.0-RC1] - released 2024-03-27
1012
### Added

src/Grant/AbstractGrant.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ protected function getBasicAuthCredentials(ServerRequestInterface $request): arr
310310
}
311311

312312
$header = $request->getHeader('Authorization')[0];
313-
if (strpos($header, 'Basic ') !== 0) {
313+
if (stripos($header, 'Basic ') !== 0) {
314314
return [null, null];
315315
}
316316

tests/Grant/AbstractGrantTest.php

+13
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,19 @@ public function testHttpBasicNotBasic(): void
7070
self::assertSame([null, null], $basicAuthMethod->invoke($grantMock, $serverRequest));
7171
}
7272

73+
public function testHttpBasicCaseInsensitive(): void
74+
{
75+
/** @var AbstractGrant $grantMock */
76+
$grantMock = $this->getMockForAbstractClass(AbstractGrant::class);
77+
$abstractGrantReflection = new ReflectionClass($grantMock);
78+
79+
$serverRequest = (new ServerRequest())->withHeader('Authorization', 'bAsIc ' . base64_encode('Open:Sesame'));
80+
$basicAuthMethod = $abstractGrantReflection->getMethod('getBasicAuthCredentials');
81+
$basicAuthMethod->setAccessible(true);
82+
83+
self::assertSame(['Open', 'Sesame'], $basicAuthMethod->invoke($grantMock, $serverRequest));
84+
}
85+
7386
public function testHttpBasicNotBase64(): void
7487
{
7588
/** @var AbstractGrant $grantMock */

0 commit comments

Comments
 (0)