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 using custom BearerTokenValidator #1653

Closed
wants to merge 1 commit into from
Closed
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
18 changes: 18 additions & 0 deletions src/Passport.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,13 @@ class Passport
*/
public static $accessTokenEntity = 'Laravel\Passport\Bridge\AccessToken';

/**
* The bearer token validator class name.
*
* @var string
*/
public static $bearerTokenValidator = 'League\OAuth2\Server\AuthorizationValidators\BearerTokenValidator';

/**
* The auth code model class name.
*
Expand Down Expand Up @@ -450,6 +457,17 @@ public static function useAccessTokenEntity($accessTokenEntity)
static::$accessTokenEntity = $accessTokenEntity;
}

/**
* Set the custom bearer token validator class name.
*
* @param string $bearerTokenValidator
* @return void
*/
public static function useBearerTokenValidator($bearerTokenValidator)
{
static::$bearerTokenValidator = $bearerTokenValidator;
}

/**
* Set the auth code model class name.
*
Expand Down
7 changes: 5 additions & 2 deletions src/PassportServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -308,9 +308,12 @@ protected function registerJWTParser()
protected function registerResourceServer()
{
$this->app->singleton(ResourceServer::class, function ($container) {
$accessTokenRepository = $container->make(Bridge\AccessTokenRepository::class);

return new ResourceServer(
$container->make(Bridge\AccessTokenRepository::class),
$this->makeCryptKey('public')
$accessTokenRepository,
$this->makeCryptKey('public'),
PaolaRuby marked this conversation as resolved.
Show resolved Hide resolved
new Passport::$bearerTokenValidator($accessTokenRepository)
);
});
}
Expand Down