File tree 2 files changed +13
-6
lines changed
tests/TestCase/Authenticator
2 files changed +13
-6
lines changed Original file line number Diff line number Diff line change @@ -43,13 +43,11 @@ class TokenAuthenticator extends AbstractAuthenticator implements StatelessInter
43
43
*/
44
44
protected function getToken (ServerRequestInterface $ request ): ?string
45
45
{
46
- $ token = $ this ->getTokenFromHeader ($ request , $ this ->getConfig ('header ' ));
47
- if ($ token === null ) {
48
- $ token = $ this ->getTokenFromQuery ($ request , $ this ->getConfig ('queryParam ' ));
49
- }
46
+ $ token = $ this ->getTokenFromHeader ($ request , $ this ->getConfig ('header ' ))
47
+ ?? $ this ->getTokenFromQuery ($ request , $ this ->getConfig ('queryParam ' ));
50
48
51
49
$ prefix = $ this ->getConfig ('tokenPrefix ' );
52
- if ($ prefix !== null && is_string ( $ token) ) {
50
+ if ($ prefix !== null && $ token !== null ) {
53
51
return $ this ->stripTokenPrefix ($ token , $ prefix );
54
52
}
55
53
@@ -65,7 +63,7 @@ protected function getToken(ServerRequestInterface $request): ?string
65
63
*/
66
64
protected function stripTokenPrefix (string $ token , string $ prefix ): string
67
65
{
68
- return str_ireplace ($ prefix . ' ' , '' , $ token );
66
+ return trim ( str_ireplace ($ prefix , '' , $ token) );
69
67
}
70
68
71
69
/**
Original file line number Diff line number Diff line change @@ -132,6 +132,15 @@ public function testTokenPrefix()
132
132
$ this ->assertInstanceOf (Result::class, $ result );
133
133
$ this ->assertSame (Result::SUCCESS , $ result ->getStatus ());
134
134
135
+ $ requestWithHeaders = $ this ->request ->withAddedHeader ('X-Dipper-Auth ' , 'dipper_mariano ' );
136
+ $ tokenAuth = new TokenAuthenticator ($ this ->identifiers , [
137
+ 'header ' => 'X-Dipper-Auth ' ,
138
+ 'tokenPrefix ' => 'dipper_ ' ,
139
+ ]);
140
+ $ result = $ tokenAuth ->authenticate ($ requestWithHeaders );
141
+ $ this ->assertInstanceOf (Result::class, $ result );
142
+ $ this ->assertSame (Result::SUCCESS , $ result ->getStatus ());
143
+
135
144
//invalid prefix
136
145
$ requestWithHeaders = $ this ->request ->withAddedHeader ('Token ' , 'bearer mariano ' );
137
146
$ tokenAuth = new TokenAuthenticator ($ this ->identifiers , [
You can’t perform that action at this time.
0 commit comments