Skip to content

Commit

Permalink
Use constant for attribute key name
Browse files Browse the repository at this point in the history
  • Loading branch information
chadicus committed Sep 15, 2018
1 parent c0f0f1a commit 5f91c5d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/Authorization.php
Expand Up @@ -14,6 +14,11 @@
*/
class Authorization implements MiddlewareInterface
{
/**
* @var string
*/
const TOKEN_ATTRIBUTE_KEY = 'oauth2-token';

/**
* OAuth2 Server
*
Expand Down Expand Up @@ -93,7 +98,7 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
foreach ($this->scopes as $scope) {
if ($this->server->verifyResourceRequest($oauth2Request, null, $scope)) {
$token = $this->server->getResourceController()->getToken();
return $handler->handle($request->withAttribute('oauth2-token', $token));
return $handler->handle($request->withAttribute(self::TOKEN_ATTRIBUTE_KEY, $token));
}
}

Expand Down
4 changes: 2 additions & 2 deletions tests/AuthorizationTest.php
Expand Up @@ -836,7 +836,7 @@ private function getNext(array $token) : callable
$test,
$token
) : ResponseInterface {
$test->assertSame($token, $request->getAttribute('oauth2-token'));
$test->assertSame($token, $request->getAttribute(Authorization::TOKEN_ATTRIBUTE_KEY));
return $response;
};
}
Expand All @@ -846,7 +846,7 @@ private function getRequestHandler(array $token = null) : RequestHandlerInterfac
$test = $this;
$callback = function (ServerRequestInterface $request) use ($test, $token) : ResponseInterface {
if ($token !== null) {
$test->assertSame($token, $request->getAttribute('oauth2-token'));
$test->assertSame($token, $request->getAttribute(Authorization::TOKEN_ATTRIBUTE_KEY));
}

return new Response();
Expand Down

0 comments on commit 5f91c5d

Please sign in to comment.