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