Skip to content

Commit

Permalink
fix: use mongolid laravel legacy model
Browse files Browse the repository at this point in the history
  • Loading branch information
djonasm committed Mar 28, 2022
1 parent ddb91ea commit 7c050fb
Show file tree
Hide file tree
Showing 18 changed files with 51 additions and 59 deletions.
16 changes: 8 additions & 8 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions src/AuthCode.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Laravel\Passport;

use MongolidLaravel\MongolidModel as Model;
use MongolidLaravel\LegacyMongolidModel as Model;

class AuthCode extends Model
{
Expand All @@ -13,8 +13,6 @@ class AuthCode extends Model

/**
* Get the client that owns the authentication code.
*
* @return Client|null
*/
public function client()
{
Expand Down
8 changes: 3 additions & 5 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Laravel\Passport;

use Mongolid\Util\LocalDateTime;
use MongolidLaravel\MongolidModel as Model;
use MongolidLaravel\LegacyMongolidModel as Model;

class Client extends Model
{
Expand Down Expand Up @@ -54,8 +54,6 @@ class Client extends Model

/**
* Get the user that the client belongs to.
*
* @return \Mongolid\LegacyRecord
*/
public function user()
{
Expand All @@ -70,7 +68,7 @@ public function user()
/**
* Get all of the authentication codes for the client.
*
* @return \Mongolid\Cursor\Cursor
* @return \Mongolid\Cursor\CursorInterface
*/
public function authCodes()
{
Expand All @@ -84,7 +82,7 @@ public function authCodes()
*
* @param array $query
*
* @return \Mongolid\Cursor\Cursor
* @return \Mongolid\Cursor\CursorInterface
*/
public function tokens(array $query = [])
{
Expand Down
2 changes: 1 addition & 1 deletion src/ClientRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function findForUser($clientId, $userId)
*
* @param mixed $userId
*
* @return \Mongolid\Cursor\Cursor
* @return \Mongolid\Cursor\CursorInterface
*/
public function forUser($userId)
{
Expand Down
4 changes: 2 additions & 2 deletions src/Console/PurgeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Illuminate\Support\Carbon;
use Laravel\Passport\Passport;
use MongoDB\BSON\UTCDateTime;
use Mongolid\Cursor\Cursor;
use Mongolid\Cursor\CursorInterface;

class PurgeCommand extends Command
{
Expand Down Expand Up @@ -62,7 +62,7 @@ public function handle()
$this->info($message);
}

protected function purgeTokens(Cursor $tokens)
protected function purgeTokens(CursorInterface $tokens)
{
foreach ($tokens as $token) {
$token->delete();
Expand Down
8 changes: 4 additions & 4 deletions src/Guards/TokenGuard.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public function client(Request $request)
}

return $this->clients->findActive(
$psr->getDocumentAttribute('oauth_client_id')
$psr->getAttribute('oauth_client_id')
);
} elseif ($request->cookie(Passport::cookie())) {
if ($token = $this->getTokenViaCookie($request)) {
Expand Down Expand Up @@ -156,7 +156,7 @@ protected function authenticateViaBearerToken($request)
// associated with the token. We will use the provider implementation which may
// be used to retrieve users from Eloquent. Next, we'll be ready to continue.
$user = $this->provider->retrieveById(
$psr->getDocumentAttribute('oauth_user_id') ?: null
$psr->getAttribute('oauth_user_id') ?: null
);

if (! $user) {
Expand All @@ -167,10 +167,10 @@ protected function authenticateViaBearerToken($request)
// to determine if the token has a given scope, etc. This will be useful during
// authorization such as within the developer's Laravel model policy classes.
$token = $this->tokens->find(
$psr->getDocumentAttribute('oauth_access_token_id')
$psr->getAttribute('oauth_access_token_id')
);

$clientId = $psr->getDocumentAttribute('oauth_client_id');
$clientId = $psr->getAttribute('oauth_client_id');

// Finally, we will verify if the client that issued this token is still valid and
// its tokens may still be used. If not, we will bail out since we don't want a
Expand Down
4 changes: 2 additions & 2 deletions src/HasApiTokens.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ trait HasApiTokens
/**
* Get all of the user's registered OAuth clients.
*
* @return \Mongolid\Cursor\Cursor
* @return \Mongolid\Cursor\CursorInterface
*/
public function clients()
{
Expand All @@ -26,7 +26,7 @@ public function clients()
/**
* Get all of the access tokens for the user.
*
* @return \Mongolid\Cursor\Cursor
* @return \Mongolid\Cursor\CursorInterface
*/
public function tokens()
{
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Controllers/AuthorizationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ protected function parseScopes($authRequest)
* Approve the authorization request.
*
* @param \League\OAuth2\Server\RequestTypes\AuthorizationRequest $authRequest
* @param \MongolidLaravel\MongolidModel $user
* @param \MongolidLaravel\LegacyMongolidModel $user
* @return \Illuminate\Http\Response
*/
protected function approveRequest($authRequest, $user)
Expand Down
4 changes: 1 addition & 3 deletions src/PersonalAccessClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Laravel\Passport;

use MongolidLaravel\MongolidModel as Model;
use MongolidLaravel\LegacyMongolidModel as Model;

class PersonalAccessClient extends Model
{
Expand All @@ -13,8 +13,6 @@ class PersonalAccessClient extends Model

/**
* Get all of the authentication codes for the client.
*
* @return Client|null
*/
public function client()
{
Expand Down
4 changes: 1 addition & 3 deletions src/RefreshToken.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
namespace Laravel\Passport;

use MongolidLaravel\MongolidModel as Model;
use MongolidLaravel\LegacyMongolidModel as Model;

class RefreshToken extends Model
{
Expand All @@ -19,8 +19,6 @@ class RefreshToken extends Model

/**
* Get the access token that the refresh token belongs to.
*
* @return \Mongolid\ActiveRecord|null
*/
public function accessToken()
{
Expand Down
2 changes: 1 addition & 1 deletion src/Token.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Laravel\Passport;

use Illuminate\Contracts\Auth\Authenticatable;
use MongolidLaravel\MongolidModel as Model;
use MongolidLaravel\LegacyMongolidModel as Model;

class Token extends Model
{
Expand Down
9 changes: 5 additions & 4 deletions src/TokenRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
namespace Laravel\Passport;

use MongoDB\BSON\UTCDateTime;
use MongolidLaravel\MongolidModel as Model;
use Mongolid\Cursor\CursorInterface;
use Mongolid\Model\ModelInterface;

class TokenRepository
{
Expand Down Expand Up @@ -57,7 +58,7 @@ public function findForUser($id, $userId)
*
* @param mixed $userId
*
* @return \Mongolid\Cursor\Cursor
* @return CursorInterface
*/
public function forUser($userId)
{
Expand All @@ -69,7 +70,7 @@ public function forUser($userId)
/**
* Get a valid token instance for the given user and client.
*
* @param Model $user
* @param ModelInterface $user
* @param \Laravel\Passport\Client $client
*
* @return \Laravel\Passport\Token|null
Expand Down Expand Up @@ -133,7 +134,7 @@ public function isAccessTokenRevoked($id)
/**
* Find a valid token for the given user and client.
*
* @param Model $user
* @param ModelInterface $user
* @param \Laravel\Passport\Client $client
*
* @return \Laravel\Passport\Token|null
Expand Down
2 changes: 1 addition & 1 deletion tests/Feature/AccessTokenControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use Laravel\Passport\Token;
use Laravel\Passport\TokenRepository;
use Lcobucci\JWT\Configuration;
use MongolidLaravel\MongolidModel as Model;
use MongolidLaravel\LegacyMongolidModel as Model;

class AccessTokenControllerTest extends PassportTestCase
{
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/AuthorizationControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public function test_request_is_approved_if_valid_token_exists()
->once()
->with($user, $clientEntity)
->andReturn($token = m::mock(Token::class));
$token->shouldReceive('getDocumentAttribute')->with('scopes')->andReturn(['scope-1']);
$token->shouldReceive('getAttribute')->with('scopes')->andReturn(['scope-1']);

$scopeRepository = m::mock(ScopeRepository::class);
$scopeRepository->shouldReceive('validateClientScopes')->with($scopes, $clientEntity)->andReturn(true);
Expand Down
12 changes: 6 additions & 6 deletions tests/Unit/CheckClientCredentialsForAnyScopeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ public function test_request_is_passed_along_if_token_is_valid()
$token = m::mock(Token::class);
$token->shouldReceive('getAttribute')->with('client')->andReturn($client);
$token->shouldReceive('getAttribute')->with('scopes')->andReturn(['*']);
$token->shouldReceive('getDocumentAttribute')->with('client')->andReturn($client);
$token->shouldReceive('getDocumentAttribute')->with('scopes')->andReturn(['*']);
$token->shouldReceive('getAttribute')->with('client')->andReturn($client);
$token->shouldReceive('getAttribute')->with('scopes')->andReturn(['*']);

$tokenRepository = m::mock(TokenRepository::class);
$tokenRepository->shouldReceive('find')->with('token')->andReturn($token);
Expand Down Expand Up @@ -65,8 +65,8 @@ public function test_request_is_passed_along_if_token_has_any_required_scope()
$client->shouldReceive('firstParty')->andReturnFalse();

$token = m::mock(Token::class);
$token->shouldReceive('getDocumentAttribute')->with('client')->andReturn($client);
$token->shouldReceive('getDocumentAttribute')->with('scopes')->andReturn(['foo', 'bar', 'baz']);
$token->shouldReceive('getAttribute')->with('client')->andReturn($client);
$token->shouldReceive('getAttribute')->with('scopes')->andReturn(['foo', 'bar', 'baz']);
$token->shouldReceive('can')->with('notfoo')->andReturnFalse();
$token->shouldReceive('can')->with('bar')->andReturnTrue();

Expand Down Expand Up @@ -120,8 +120,8 @@ public function test_exception_is_thrown_if_token_does_not_have_required_scope()
$client->shouldReceive('firstParty')->andReturnFalse();

$token = m::mock(Token::class);
$token->shouldReceive('getDocumentAttribute')->with('client')->andReturn($client);
$token->shouldReceive('getDocumentAttribute')->with('scopes')->andReturn(['foo', 'bar']);
$token->shouldReceive('getAttribute')->with('client')->andReturn($client);
$token->shouldReceive('getAttribute')->with('scopes')->andReturn(['foo', 'bar']);
$token->shouldReceive('can')->with('baz')->andReturnFalse();
$token->shouldReceive('can')->with('notbar')->andReturnFalse();

Expand Down
12 changes: 6 additions & 6 deletions tests/Unit/CheckClientCredentialsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ public function test_request_is_passed_along_if_token_is_valid()
$client->shouldReceive('firstParty')->andReturnFalse();

$token = m::mock(Token::class);
$token->shouldReceive('getDocumentAttribute')->with('client')->andReturn($client);
$token->shouldReceive('getDocumentAttribute')->with('scopes')->andReturn(['*']);
$token->shouldReceive('getAttribute')->with('client')->andReturn($client);
$token->shouldReceive('getAttribute')->with('scopes')->andReturn(['*']);

$tokenRepository = m::mock(TokenRepository::class);
$tokenRepository->shouldReceive('find')->with('token')->andReturn($token);
Expand Down Expand Up @@ -63,8 +63,8 @@ public function test_request_is_passed_along_if_token_and_scope_are_valid()
$client->shouldReceive('firstParty')->andReturnFalse();

$token = m::mock(Token::class);
$token->shouldReceive('getDocumentAttribute')->with('client')->andReturn($client);
$token->shouldReceive('getDocumentAttribute')->with('scopes')->andReturn(['see-profile']);
$token->shouldReceive('getAttribute')->with('client')->andReturn($client);
$token->shouldReceive('getAttribute')->with('scopes')->andReturn(['see-profile']);
$token->shouldReceive('cant')->with('see-profile')->andReturnFalse();

$tokenRepository = m::mock(TokenRepository::class);
Expand Down Expand Up @@ -117,8 +117,8 @@ public function test_exception_is_thrown_if_token_does_not_have_required_scopes(
$client->shouldReceive('firstParty')->andReturnFalse();

$token = m::mock(Token::class);
$token->shouldReceive('getDocumentAttribute')->with('client')->andReturn($client);
$token->shouldReceive('getDocumentAttribute')->with('scopes')->andReturn(['foo', 'notbar']);
$token->shouldReceive('getAttribute')->with('client')->andReturn($client);
$token->shouldReceive('getAttribute')->with('scopes')->andReturn(['foo', 'notbar']);
$token->shouldReceive('cant')->with('foo')->andReturnFalse();
$token->shouldReceive('cant')->with('bar')->andReturnTrue();

Expand Down
1 change: 0 additions & 1 deletion tests/Unit/PersonalAccessTokenControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use Laravel\Passport\TokenRepository;
use Mockery as m;
use MongoDB\BSON\ObjectId;
use Mongolid\Cursor\Cursor;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\Response;

Expand Down
Loading

0 comments on commit 7c050fb

Please sign in to comment.