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

Restrictions with models #176

Open
alejosv opened this issue Oct 22, 2022 · 0 comments
Open

Restrictions with models #176

alejosv opened this issue Oct 22, 2022 · 0 comments

Comments

@alejosv
Copy link

alejosv commented Oct 22, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant