Skip to content

Instantly share code, notes, and snippets.

@fendis0709
Created November 22, 2021 03:50
Show Gist options
  • Save fendis0709/e86f25bfa4006e20ca6a96eed8df9b4e to your computer and use it in GitHub Desktop.
Save fendis0709/e86f25bfa4006e20ca6a96eed8df9b4e to your computer and use it in GitHub Desktop.
Check file private and public keys before generate token
class AuthServiceProvider extends ServiceProvider
{
/**
* Register any authentication / authorization services.
*
* @return void
*/
public function boot()
{
$this->registerPolicies();
// Register the Passport routes
Passport::routes();
// Check the Oauth Key before set the token lifetime
// This will help when you need to run "php artisan passport:install" on server production
$privateKey = File::exists(storage_path('oauth-private.key'));
$publicKey = File::exists(storage_path('oauth-public.key'));
if ($privateKey && $publicKey) {
$server = $this->app->make(\League\OAuth2\Server\AuthorizationServer::class);
$server->enableGrantType(new \Laravel\Passport\Bridge\PersonalAccessGrant(), new \DateInterval('P7D'));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment