AuthServiceProvider.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. namespace App\Providers;
  3. use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
  4. use Laravel\Passport\Passport;
  5. use Gate;
  6. class AuthServiceProvider extends ServiceProvider
  7. {
  8. /**
  9. * The policy mappings for the application.
  10. *
  11. * @var array
  12. */
  13. protected $policies = [
  14. 'App\Model' => 'App\Policies\ModelPolicy',
  15. ];
  16. /**
  17. * Register any authentication / authorization services.
  18. *
  19. * @return void
  20. */
  21. public function boot()
  22. {
  23. $this->registerPolicies();
  24. if(config('pixelfed.oauth_enabled')) {
  25. Passport::routes(null, ['middleware' => ['twofactor', \Fruitcake\Cors\HandleCors::class]]);
  26. Passport::tokensExpireIn(now()->addDays(config('instance.oauth.token_expiration', 15)));
  27. Passport::refreshTokensExpireIn(now()->addDays(config('instance.oauth.refresh_expiration', 30)));
  28. Passport::enableImplicitGrant();
  29. if(config('instance.oauth.pat.enabled')) {
  30. Passport::personalAccessClientId(config('instance.oauth.pat.id'));
  31. }
  32. Passport::setDefaultScope([
  33. 'read',
  34. 'write',
  35. 'follow',
  36. ]);
  37. Passport::tokensCan([
  38. 'read' => 'Full read access to your account',
  39. 'write' => 'Full write access to your account',
  40. 'follow' => 'Ability to follow other profiles',
  41. 'push' => ''
  42. ]);
  43. }
  44. Gate::define('viewWebSocketsDashboard', function ($user = null) {
  45. return $user->is_admin;
  46. });
  47. }
  48. }