dusterio/lumen-passport

Restrictions with models

alejosv opened this issue · 0 comments

I'm working with this package, my project I force myself in rename the passport's tables and this issue I can resolved created a own provider as follows:

<?php

namespace App\Providers;

use Laravel\Passport\Passport;
use Dusterio\LumenPassport\PassportServiceProvider;
use App\Models\{User, Token, Client, AuthCode, PersonalAccessClient, RefreshToken};

class TelesaludServiceProvider extends PassportServiceProvider 
{ 

    public function boot()
    {
        
        Passport::useTokenModel(Token::class);
        Passport::useClientModel(Client::class);
        Passport::useAuthCodeModel(AuthCode::class);
        Passport::usePersonalAccessClientModel(PersonalAccessClient::class);
        Passport::useRefreshTokenModel(RefreshToken::class);
        
    }

}

Where each model in my project I haved to renamed the table as follows:

<?php

namespace App\Models;

use Laravel\Passport\Token as TokenPassport;

class Token extends TokenPassport 
{
    /**
     * The database table used by the model.
     *
     * @var string
     */
    protected $table = 'telesa_oauth_access_tokens';
}

The problem is in this code:

$query = Token::where('user_id', $token->user_id)->where('client_id', $token->client_id);
if ($tokenId) {
$query->where('id', '<>', $tokenId);
}
$query->update(['revoked' => true]);

$count = DB::table('oauth_refresh_tokens')->where('expires_at', '<', new DateTime())->delete();
if (Passport::$refreshTokensExpireAt && Passport::$tokensExpireAt) {
$difference = Passport::$refreshTokensExpireAt->getTimestamp() - Passport::$tokensExpireAt->getTimestamp();
// We assume it's safe to delete tokens that cannot be refreshed anyway
$count += DB::table('oauth_access_tokens')
->where('expires_at', '<', (new DateTime())->setTimestamp(time() - $difference))
->delete();

So, your package call the table with the Passport original value, so if I make a print at Token::class I have: Laravel\Passport\Token when the correct behavior is get App\Model\Token

I'm new in Lumel and Passport but I suppose this is the right way to can use different tables names