From 748a3be46d80a4d9e5ee3e2da6e5131852307d15 Mon Sep 17 00:00:00 2001 From: delthas Date: Mon, 31 Aug 2020 23:16:42 +0200 Subject: [PATCH] Add support for configurable OAuth tokens and refresh tokens lifetime Previously, the lifetime of tokens and refresh tokens was hardcoded at 15 and 30 days. Some instances administrators may wish to change these values. This makes these two values configurable with the two .env variables: OAUTH_TOKEN_DAYS and OAUTH_REFRESH_DAYS which are the lifetime in days for these two tokens and refresh tokens. --- app/Providers/AuthServiceProvider.php | 4 ++-- config/instance.php | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/app/Providers/AuthServiceProvider.php b/app/Providers/AuthServiceProvider.php index 8eb85150b..5c7fb7ff6 100644 --- a/app/Providers/AuthServiceProvider.php +++ b/app/Providers/AuthServiceProvider.php @@ -28,8 +28,8 @@ class AuthServiceProvider extends ServiceProvider if(config('pixelfed.oauth_enabled')) { Passport::routes(null, ['middleware' => ['twofactor', \Fruitcake\Cors\HandleCors::class]]); - Passport::tokensExpireIn(now()->addDays(15)); - Passport::refreshTokensExpireIn(now()->addDays(30)); + Passport::tokensExpireIn(now()->addDays(config('instance.oauth.token_expiration'))); + Passport::refreshTokensExpireIn(now()->addDays(config('instance.oauth.refresh_expiration'))); Passport::enableImplicitGrant(); if(config('instance.oauth.pat.enabled')) { Passport::personalAccessClientId(config('instance.oauth.pat.id')); diff --git a/config/instance.php b/config/instance.php index e8047f3ec..489118f0e 100644 --- a/config/instance.php +++ b/config/instance.php @@ -55,6 +55,8 @@ return [ ], 'oauth' => [ + 'token_expiration' => env('OAUTH_TOKEN_DAYS', 15), + 'refresh_expiration' => env('OAUTH_REFRESH_DAYS', 30), 'pat' => [ 'enabled' => env('OAUTH_PAT_ENABLED', false), 'id' => env('OAUTH_PAT_ID'),