Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[9.x] Switch from getKey() to getAuthIdentifier() to match Laravel core #1134

Merged
merged 3 commits into from
Dec 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion src/Http/Controllers/AuthorizationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ protected function parseScopes($authRequest)
*/
protected function approveRequest($authRequest, $user)
{
$authRequest->setUser(new User($user->getKey()));
$authRequest->setUser(new User($user->getAuthIdentifier()));

$authRequest->setAuthorizationApproved(true);

Expand Down
4 changes: 2 additions & 2 deletions src/Http/Controllers/AuthorizedAccessTokenController.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function __construct(TokenRepository $tokenRepository)
*/
public function forUser(Request $request)
{
$tokens = $this->tokenRepository->forUser($request->user()->getKey());
$tokens = $this->tokenRepository->forUser($request->user()->getAuthIdentifier());

return $tokens->load('client')->filter(function ($token) {
return ! $token->client->firstParty() && ! $token->revoked;
Expand All @@ -51,7 +51,7 @@ public function forUser(Request $request)
public function destroy(Request $request, $tokenId)
{
$token = $this->tokenRepository->findForUser(
$tokenId, $request->user()->getKey()
$tokenId, $request->user()->getAuthIdentifier()
);

if (is_null($token)) {
Expand Down
8 changes: 4 additions & 4 deletions src/Http/Controllers/ClientController.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function __construct(
*/
public function forUser(Request $request)
{
$userId = $request->user()->getKey();
$userId = $request->user()->getAuthIdentifier();

return $this->clients->activeForUser($userId)->makeVisible('secret');
}
Expand All @@ -77,7 +77,7 @@ public function store(Request $request)
])->validate();

return $this->clients->create(
$request->user()->getKey(), $request->name, $request->redirect,
$request->user()->getAuthIdentifier(), $request->name, $request->redirect,
false, false, (bool) $request->input('confidential', true)
)->makeVisible('secret');
}
Expand All @@ -91,7 +91,7 @@ public function store(Request $request)
*/
public function update(Request $request, $clientId)
{
$client = $this->clients->findForUser($clientId, $request->user()->getKey());
$client = $this->clients->findForUser($clientId, $request->user()->getAuthIdentifier());

if (! $client) {
return new Response('', 404);
Expand All @@ -116,7 +116,7 @@ public function update(Request $request, $clientId)
*/
public function destroy(Request $request, $clientId)
{
$client = $this->clients->findForUser($clientId, $request->user()->getKey());
$client = $this->clients->findForUser($clientId, $request->user()->getAuthIdentifier());

if (! $client) {
return new Response('', 404);
Expand Down
4 changes: 2 additions & 2 deletions src/Http/Controllers/PersonalAccessTokenController.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function __construct(TokenRepository $tokenRepository, ValidationFactory
*/
public function forUser(Request $request)
{
$tokens = $this->tokenRepository->forUser($request->user()->getKey());
$tokens = $this->tokenRepository->forUser($request->user()->getAuthIdentifier());

return $tokens->load('client')->filter(function ($token) {
return $token->client->personal_access_client && ! $token->revoked;
Expand Down Expand Up @@ -80,7 +80,7 @@ public function store(Request $request)
public function destroy(Request $request, $tokenId)
{
$token = $this->tokenRepository->findForUser(
$tokenId, $request->user()->getKey()
$tokenId, $request->user()->getAuthIdentifier()
);

if (is_null($token)) {
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Controllers/RetrievesAuthRequestFromSession.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ protected function getAuthRequestFromSession(Request $request)
throw new Exception('Authorization request was not present in the session.');
}

$authRequest->setUser(new User($request->user()->getKey()));
$authRequest->setUser(new User($request->user()->getAuthIdentifier()));

$authRequest->setAuthorizationApproved(true);
});
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Controllers/TransientTokenController.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function __construct(ApiTokenCookieFactory $cookieFactory)
public function refresh(Request $request)
{
return (new Response('Refreshed.'))->withCookie($this->cookieFactory->make(
$request->user()->getKey(), $request->session()->token()
$request->user()->getAuthIdentifier(), $request->session()->token()
));
}
}
2 changes: 1 addition & 1 deletion src/Http/Middleware/CreateFreshApiToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function handle($request, Closure $next, $guard = null)

if ($this->shouldReceiveFreshToken($request, $response)) {
$response->withCookie($this->cookieFactory->make(
$request->user($this->guard)->getKey(), $request->session()->token()
$request->user($this->guard)->getAuthIdentifier(), $request->session()->token()
));
}

Expand Down
4 changes: 2 additions & 2 deletions src/TokenRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function forUser($userId)
public function getValidToken($user, $client)
{
return $client->tokens()
->whereUserId($user->getKey())
->whereUserId($user->getAuthIdentifier())
->where('revoked', 0)
->where('expires_at', '>', Carbon::now())
->first();
Expand Down Expand Up @@ -115,7 +115,7 @@ public function isAccessTokenRevoked($id)
public function findValidToken($user, $client)
{
return $client->tokens()
->whereUserId($user->getKey())
->whereUserId($user->getAuthIdentifier())
->where('revoked', 0)
->where('expires_at', '>', Carbon::now())
->latest('expires_at')
Expand Down
2 changes: 1 addition & 1 deletion tests/ApproveAuthorizationControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class ApproveAuthorizationControllerFakeUser
{
public $id = 1;

public function getKey()
public function getAuthIdentifier()
{
return $this->id;
}
Expand Down
4 changes: 2 additions & 2 deletions tests/AuthorizationControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public function test_request_is_approved_if_valid_token_exists()

$request = m::mock(Request::class);
$request->shouldReceive('user')->once()->andReturn($user = m::mock());
$user->shouldReceive('getKey')->andReturn(1);
$user->shouldReceive('getAuthIdentifier')->andReturn(1);
$request->shouldNotReceive('session');

$authRequest->shouldReceive('getClient->getIdentifier')->once()->andReturn(1);
Expand Down Expand Up @@ -155,7 +155,7 @@ public function test_request_is_approved_if_client_can_skip_authorization()

$request = m::mock(Request::class);
$request->shouldReceive('user')->once()->andReturn($user = m::mock());
$user->shouldReceive('getKey')->andReturn(1);
$user->shouldReceive('getAuthIdentifier')->andReturn(1);
$request->shouldNotReceive('session');

$authRequest->shouldReceive('getClient->getIdentifier')->once()->andReturn(1);
Expand Down
6 changes: 3 additions & 3 deletions tests/AuthorizedAccessTokenControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function test_tokens_can_be_retrieved_for_users()

$request->setUserResolver(function () use ($token1, $token2) {
$user = m::mock();
$user->shouldReceive('getKey')->andReturn(1);
$user->shouldReceive('getAuthIdentifier')->andReturn(1);

return $user;
});
Expand All @@ -81,7 +81,7 @@ public function test_tokens_can_be_deleted()

$request->setUserResolver(function () {
$user = m::mock();
$user->shouldReceive('getKey')->andReturn(1);
$user->shouldReceive('getAuthIdentifier')->andReturn(1);

return $user;
});
Expand All @@ -99,7 +99,7 @@ public function test_not_found_response_is_returned_if_user_doesnt_have_token()

$request->setUserResolver(function () {
$user = m::mock();
$user->shouldReceive('getKey')->andReturn(1);
$user->shouldReceive('getAuthIdentifier')->andReturn(1);

return $user;
});
Expand Down
10 changes: 5 additions & 5 deletions tests/ClientControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public function test_clients_can_be_updated()

$request->setUserResolver(function () {
$user = m::mock();
$user->shouldReceive('getKey')->andReturn(1);
$user->shouldReceive('getAuthIdentifier')->andReturn(1);

return $user;
});
Expand Down Expand Up @@ -157,7 +157,7 @@ public function test_404_response_if_client_doesnt_belong_to_user()

$request->setUserResolver(function () {
$user = m::mock();
$user->shouldReceive('getKey')->andReturn(1);
$user->shouldReceive('getAuthIdentifier')->andReturn(1);

return $user;
});
Expand All @@ -183,7 +183,7 @@ public function test_clients_can_be_deleted()

$request->setUserResolver(function () {
$user = m::mock();
$user->shouldReceive('getKey')->andReturn(1);
$user->shouldReceive('getAuthIdentifier')->andReturn(1);

return $user;
});
Expand Down Expand Up @@ -212,7 +212,7 @@ public function test_404_response_if_client_doesnt_belong_to_user_on_delete()

$request->setUserResolver(function () {
$user = m::mock();
$user->shouldReceive('getKey')->andReturn(1);
$user->shouldReceive('getAuthIdentifier')->andReturn(1);

return $user;
});
Expand All @@ -233,7 +233,7 @@ class ClientControllerFakeUser
{
public $id = 1;

public function getKey()
public function getAuthIdentifier()
{
return $this->id;
}
Expand Down
4 changes: 2 additions & 2 deletions tests/CreateFreshApiTokenTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function testShouldReceiveAFreshToken()

$guard = 'guard';
$user = m::mock()
->shouldReceive('getKey')
->shouldReceive('getAuthIdentifier')
->andReturn($userKey = 1)
->getMock();

Expand Down Expand Up @@ -99,7 +99,7 @@ public function testShouldNotReceiveAFreshTokenForResponseThatAlreadyHasToken()

$request->setUserResolver(function () {
return m::mock()
->shouldReceive('getKey')
->shouldReceive('getAuthIdentifier')
->andReturn(1)
->getMock();
});
Expand Down
2 changes: 1 addition & 1 deletion tests/DenyAuthorizationControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ class DenyAuthorizationControllerFakeUser
{
public $id = 1;

public function getKey()
public function getAuthIdentifier()
{
return $this->id;
}
Expand Down
6 changes: 3 additions & 3 deletions tests/PersonalAccessTokenControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function test_tokens_can_be_retrieved_for_users()

$request->setUserResolver(function () use ($token1, $token2) {
$user = m::mock();
$user->shouldReceive('getKey')->andReturn(1);
$user->shouldReceive('getAuthIdentifier')->andReturn(1);

return $user;
});
Expand Down Expand Up @@ -98,7 +98,7 @@ public function test_tokens_can_be_deleted()

$request->setUserResolver(function () {
$user = m::mock();
$user->shouldReceive('getKey')->andReturn(1);
$user->shouldReceive('getAuthIdentifier')->andReturn(1);

return $user;
});
Expand All @@ -120,7 +120,7 @@ public function test_not_found_response_is_returned_if_user_doesnt_have_token()

$request->setUserResolver(function () {
$user = m::mock();
$user->shouldReceive('getKey')->andReturn(1);
$user->shouldReceive('getAuthIdentifier')->andReturn(1);

return $user;
});
Expand Down
2 changes: 1 addition & 1 deletion tests/TransientTokenControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function test_token_can_be_refreshed()

$request = m::mock(Request::class);
$request->shouldReceive('user')->andReturn($user = m::mock());
$user->shouldReceive('getKey')->andReturn(1);
$user->shouldReceive('getAuthIdentifier')->andReturn(1);
$request->shouldReceive('session->token')->andReturn('token');

$controller = new TransientTokenController($cookieFactory);
Expand Down