From 10702cef414eec6611086117565d565f8c35e8ee Mon Sep 17 00:00:00 2001 From: bye Date: Wed, 29 May 2024 18:33:57 +0100 Subject: [PATCH] i dont know whats in this commit hopefully it's good --- accounts_handler.php | 34 ++++++++++++-- admin.php | 5 ++ admin_accounts.php | 6 +-- admin_create_token.php | 86 ++++++++++++++++++++++++++++++++++ api_handler.php | 65 +++++++++++++++++++++----- assets/buttons/signinwith.svg | 88 +++++++++++++++++++++++++++++++++++ head.php | 2 +- index.php | 2 + landing.php | 32 +++++++++++-- login_external_basic.php | 41 +++++++++++----- profile.php | 48 +------------------ settings_account.php | 79 +++++++++++++++++++++++++++++++ signin.php | 2 +- styles/colours.css | 6 +++ styles/profiles.css | 8 ++++ styles/types.css | 4 ++ 16 files changed, 426 insertions(+), 82 deletions(-) create mode 100644 admin_create_token.php create mode 100644 assets/buttons/signinwith.svg create mode 100644 settings_account.php diff --git a/accounts_handler.php b/accounts_handler.php index 34e6c0a..1ae09c3 100644 --- a/accounts_handler.php +++ b/accounts_handler.php @@ -30,7 +30,7 @@ function get_display_name($bcid, $use_bcid_fallback=true, $put_bcid_in_parenthes // Tokens so apps can get VERY BASIC information -function generate_basic_access_token($bcid): array +function generate_basic_access_token($bcid, $application_id=""): array { // Returns an access token, a refresh token and an expiry timestamp. @@ -42,14 +42,42 @@ function generate_basic_access_token($bcid): array // echo $access_token . ":" . $refresh_token; + if ($application_id) { + db_execute( + "INSERT INTO tokens (access_token, refresh_token, expiry, owner_id, application_id, permissions) VALUES (?,?,?,?,?, (1<<0 | 1<<1))", + [$access_token, $refresh_token, $expiry, $bcid, $application_id] + ); + } else { + db_execute( + "INSERT INTO tokens (access_token, refresh_token, expiry, owner_id, permissions) VALUES (?,?,?,?, (1<<0 | 1<<1))", + [$access_token, $refresh_token, $expiry, $bcid] + ); + } + + return [ + "access" => $access_token, + "refresh" => $refresh_token, + "expiry" => $expiry, + "id" => $bcid + ]; +} + +function generate_token($bcid, $application_id=null, $permissions=0): array { + $access_token = md5(uniqid(more_entropy: true).rand(1000000, 9999999)); + $refresh_token = md5(uniqid("rfish").rand(1000000, 9999999)); + + $valid_time = 12; // in hours + $expiry = time() + ($valid_time * 60 * 60); + db_execute( - "INSERT INTO tokens (access_token, refresh_token, expiry, owner_id) VALUES (?,?,?,?)", - [$access_token, $refresh_token, $expiry, $bcid] + "INSERT INTO tokens (access_token, refresh_token, expiry, owner_id, application_id, permissions, type) VALUES (?,?,?,?,?,?, 'oauth')", + [$access_token, $refresh_token, $expiry, $bcid, $application_id, $permissions] ); return [ "access" => $access_token, "refresh" => $refresh_token, + "permissions" => $permissions, "expiry" => $expiry, "id" => $bcid ]; diff --git a/admin.php b/admin.php index d92d029..efb0b73 100644 --- a/admin.php +++ b/admin.php @@ -18,6 +18,11 @@ +

API

+ +

Init