diff --git a/src/app/Providers/AuthServiceProvider.php b/src/app/Providers/AuthServiceProvider.php index f9b1019e..b1541e94 100644 --- a/src/app/Providers/AuthServiceProvider.php +++ b/src/app/Providers/AuthServiceProvider.php @@ -1,41 +1,26 @@ */ protected $policies = [ ]; /** * Register any authentication / authorization services. * * @return void */ public function boot() { $this->registerPolicies(); - - Passport::tokensCan([ - 'api' => 'Access API', - 'mfa' => 'Access MFA API', - ]); - - Passport::tokensExpireIn(now()->addMinutes(\config('auth.token_expiry_minutes'))); - Passport::refreshTokensExpireIn(now()->addMinutes(\config('auth.refresh_token_expiry_minutes'))); - Passport::personalAccessTokensExpireIn(now()->addMonths(6)); - - Passport::useClientModel(\App\Auth\PassportClient::class); - Passport::tokenModel()::observe(\App\Observers\Passport\TokenObserver::class); } } diff --git a/src/app/Providers/PassportServiceProvider.php b/src/app/Providers/PassportServiceProvider.php index 1a289f55..eea3b547 100644 --- a/src/app/Providers/PassportServiceProvider.php +++ b/src/app/Providers/PassportServiceProvider.php @@ -1,52 +1,72 @@ 'Access API', + 'mfa' => 'Access MFA API', + ]); + + Passport::tokensExpireIn(now()->addMinutes(\config('auth.token_expiry_minutes'))); + Passport::refreshTokensExpireIn(now()->addMinutes(\config('auth.refresh_token_expiry_minutes'))); + Passport::personalAccessTokensExpireIn(now()->addMonths(6)); + + Passport::useClientModel(\App\Auth\PassportClient::class); + Passport::tokenModel()::observe(\App\Observers\Passport\TokenObserver::class); + } + /** * Make the authorization service instance. * * @return \League\OAuth2\Server\AuthorizationServer */ public function makeAuthorizationServer() { return new AuthorizationServer( $this->app->make(Bridge\ClientRepository::class), $this->app->make(Bridge\AccessTokenRepository::class), $this->app->make(Bridge\ScopeRepository::class), $this->makeCryptKey('private'), $this->makeEncryptionKey(app('encrypter')->getKey()) ); } /** * Create a Key instance for encrypting the refresh token * * Based on https://github.com/laravel/passport/pull/820 * * @param string $keyBytes * @return \Defuse\Crypto\Key */ private function makeEncryptionKey($keyBytes) { // First, we will encode Laravel's encryption key into a format that the Defuse\Crypto\Key class can use, // so we can instantiate a new Key object. We need to do this as the Key class has a private constructor method // which means we cannot directly instantiate the class based on our Laravel encryption key. $encryptionKeyAscii = EncryptionEncoding::saveBytesToChecksummedAsciiSafeString( EncryptionKey::KEY_CURRENT_VERSION, $keyBytes ); // Instantiate a Key object so we can take advantage of significantly faster encryption/decryption // from https://github.com/thephpleague/oauth2-server/pull/814. The improvement is 200x-300x faster. return EncryptionKey::loadFromAsciiSafeString($encryptionKeyAscii); } }