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

[11.x] Allow overriding the AccessToken class #1638

Merged
merged 1 commit into from
Feb 21, 2023
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
3 changes: 2 additions & 1 deletion src/Bridge/AccessTokenRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use DateTime;
use Illuminate\Contracts\Events\Dispatcher;
use Laravel\Passport\Events\AccessTokenCreated;
use Laravel\Passport\Passport;
use Laravel\Passport\TokenRepository;
use League\OAuth2\Server\Entities\AccessTokenEntityInterface;
use League\OAuth2\Server\Entities\ClientEntityInterface;
Expand Down Expand Up @@ -46,7 +47,7 @@ public function __construct(TokenRepository $tokenRepository, Dispatcher $events
*/
public function getNewToken(ClientEntityInterface $clientEntity, array $scopes, $userIdentifier = null)
{
return new AccessToken($userIdentifier, $scopes, $clientEntity);
return new Passport::$accessTokenEntity($userIdentifier, $scopes, $clientEntity);
}

/**
Expand Down
18 changes: 18 additions & 0 deletions src/Passport.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,13 @@ class Passport
*/
public static $keyPath;

/**
* The access token entity class name.
*
* @var string
*/
public static $accessTokenEntity = 'Laravel\Passport\Bridge\AccessToken';

/**
* The auth code model class name.
*
Expand Down Expand Up @@ -432,6 +439,17 @@ public static function keyPath($file)
: storage_path($file);
}

/**
* Set the access token entity class name.
*
* @param string $accessTokenEntity
* @return void
*/
public static function useAccessTokenEntity($accessTokenEntity)
{
static::$accessTokenEntity = $accessTokenEntity;
}

/**
* Set the auth code model class name.
*
Expand Down