Skip to content

Commit

Permalink
Merge pull request #7 from ebaranauskas/BASIC-AUTH-FIX
Browse files Browse the repository at this point in the history
Authorization header fixed for Basic AUTH
  • Loading branch information
vbartusevicius authored Nov 18, 2020
2 parents 6801176 + 27b78c9 commit 9ebe561
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## 2.4.1
### Fixed
- Basic authentication `Authorization` header must have prefix `Basic `

## 2.4.0
### Added
- Added ability to pass any configuration without whitelisting to the client
Expand Down
4 changes: 3 additions & 1 deletion src/Middleware/Authentication/BasicAuthentication.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@ private function buildAuthHeader(array $auth)
);
}

return base64_encode(sprintf(
$credentials = base64_encode(sprintf(
'%s:%s',
$auth['username'],
$auth['password']
));

return sprintf('Basic %s', $credentials);
}
}
2 changes: 1 addition & 1 deletion tests/AuthenticationMiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public function testBasicAuthenticationAdded()
$auth = $request->getHeaderLine('Authorization');

$this->assertSame(RequestMethodInterface::METHOD_GET, $request->getMethod());
$this->assertSame(base64_encode(sprintf('%s:%s', $username, $password)), $auth);
$this->assertSame('Basic ' . base64_encode(sprintf('%s:%s', $username, $password)), $auth);
}

/**
Expand Down

0 comments on commit 9ebe561

Please sign in to comment.