Skip to content

Commit

Permalink
allow overriding the AccessToken class (#1638)
Browse files Browse the repository at this point in the history
  • Loading branch information
hafezdivandari authored Feb 21, 2023
1 parent d95c095 commit 587aa14
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
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

0 comments on commit 587aa14

Please sign in to comment.