Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/Authenticator/TokenAuthenticator.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,12 @@ protected function getToken(ServerRequestInterface $request): ?string
*/
protected function stripTokenPrefix(string $token, string $prefix): string
{
return trim(str_ireplace($prefix, '', $token));
$prefixLength = mb_strlen($prefix);
if (mb_substr(mb_strtolower($token), 0, $prefixLength) === mb_strtolower($prefix)) {
$token = mb_substr($token, $prefixLength);
}

return trim($token);
}

/**
Expand Down
10 changes: 10 additions & 0 deletions tests/TestCase/Authenticator/TokenAuthenticatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,16 @@ public function testTokenPrefix()
$result = $tokenAuth->authenticate($requestWithHeaders);
$this->assertInstanceOf(Result::class, $result);
$this->assertSame(Result::FAILURE_IDENTITY_NOT_FOUND, $result->getStatus());

// should not modify in between
$requestWithHeaders = $this->request->withAddedHeader('X-Dipper-Auth', 'auth-token-13');
Comment thread
dereuromark marked this conversation as resolved.
Outdated
$tokenAuth = new TokenAuthenticator($this->identifiers, [
'header' => 'X-Dipper-Auth',
'tokenPrefix' => 'token_',
]);
$result = $tokenAuth->authenticate($requestWithHeaders);
$this->assertInstanceOf(Result::class, $result);
$this->assertSame(Result::SUCCESS, $result->getStatus());
}

/**
Expand Down
Loading