diff options
author | Jesse Morgan <jesse@jesterpm.net> | 2025-02-23 17:01:31 -0800 |
---|---|---|
committer | Jesse Morgan <jesse@jesterpm.net> | 2025-02-23 17:01:31 -0800 |
commit | 2e022f842d4b9a118bc99ec6bce5914b74b0240e (patch) | |
tree | f4f9811992b0137008aa3626af1326d1312a1050 | |
parent | 9cef96e19452ec5fd9857ef64eca48e7c8690b5d (diff) | |
parent | d347e8286bae38b3949f6e0f58d8ab8632cd9c0e (diff) |
Merge branch 'reauthorize' into local-installlocal-install
-rw-r--r-- | controllers/auth.php | 5 | ||||
-rw-r--r-- | controllers/controllers.php | 12 | ||||
-rw-r--r-- | schema/migrations/0013.sql | 2 | ||||
-rw-r--r-- | schema/mysql.sql | 1 | ||||
-rw-r--r-- | schema/sqlite.sql | 1 |
5 files changed, 20 insertions, 1 deletions
diff --git a/controllers/auth.php b/controllers/auth.php index 9dcc81d..50dbc02 100644 --- a/controllers/auth.php +++ b/controllers/auth.php @@ -175,6 +175,10 @@ $app->get('/auth/callback', function() use($app) { $user->token_endpoint = $tokenEndpoint; $user->micropub_endpoint = $micropubEndpoint; $user->micropub_access_token = $token['response']['access_token']; + if(is_numeric($token['response']['expires_in'])) { + $expiration = time() + $token['response']['expires_in']; + $user->micropub_token_expiration = date('Y-m-d H:i:s', $expiration); + } $user->micropub_scope = $token['response']['scope']; $user->micropub_response = $token['raw_response']; $user->save(); @@ -236,6 +240,7 @@ $app->post('/auth/reset', function() use($app) { $user->micropub_media_endpoint = ''; $user->micropub_scope = ''; $user->micropub_access_token = ''; + $user->micropub_token_expiration = ''; $user->syndication_targets = ''; $user->supported_post_types = ''; $user->save(); diff --git a/controllers/controllers.php b/controllers/controllers.php index 153c9e2..de497c9 100644 --- a/controllers/controllers.php +++ b/controllers/controllers.php @@ -30,7 +30,17 @@ function require_login(&$app, $redirect=true) { $app->redirect('/', 302); return false; } else { - return ORM::for_table('users')->find_one($_SESSION['user_id']); + $user = ORM::for_table('users')->find_one($_SESSION['user_id']); + if(isset($user->micropub_token_expiration)) { + $now = new DateTime(); + $expiration = new DateTime($user->micropub_token_expiration); + if($now > $expiration) { + header('X-Error: TokenExpired'); + $app->redirect('/auth/start?'.http_build_query(array('me' => $user->url)), 302); + return false; + } + } + return $user; } } diff --git a/schema/migrations/0013.sql b/schema/migrations/0013.sql new file mode 100644 index 0000000..709ad21 --- /dev/null +++ b/schema/migrations/0013.sql @@ -0,0 +1,2 @@ +ALTER TABLE users +ADD COLUMN `micropub_token_expiration` datetime DEFAULT NULL; diff --git a/schema/mysql.sql b/schema/mysql.sql index 3d2b45e..4a7d477 100644 --- a/schema/mysql.sql +++ b/schema/mysql.sql @@ -6,6 +6,7 @@ CREATE TABLE `users` ( `micropub_endpoint` varchar(255) DEFAULT NULL, `micropub_media_endpoint` varchar(255) DEFAULT NULL, `micropub_access_token` text, + `micropub_token_expiration` datetime DEFAULT NULL, `micropub_scope` varchar(255) DEFAULT NULL, `micropub_response` text, `micropub_slug_field` varchar(255) NOT NULL DEFAULT 'mp-slug', diff --git a/schema/sqlite.sql b/schema/sqlite.sql index 3283960..7265fd1 100644 --- a/schema/sqlite.sql +++ b/schema/sqlite.sql @@ -6,6 +6,7 @@ CREATE TABLE users ( micropub_endpoint TEXT, micropub_media_endpoint TEXT, micropub_access_token TEXT, + micropub_token_expiration datetime, micropub_scope TEXT, micropub_response TEXT, micropub_slug_field TEXT default 'mp-slug', |