From 9d2ee54790f9dedf3c1b3659ee312afcfb007fe2 Mon Sep 17 00:00:00 2001 From: halcy Date: Sun, 27 Nov 2022 22:53:07 +0200 Subject: Add client auth data to access token file --- CHANGELOG.rst | 1 + docs/index.rst | 18 ++++++++++++------ mastodon/Mastodon.py | 14 ++++++++++++-- 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 2934f0d..cad7851 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -13,6 +13,7 @@ v1.8.0 (in progress) * Make the documentation a bit neater (thanks dieseltravis) * Add the domain blocking admin API (`admin_domain_blocks`, `admin_domain_block`, `admin_update_domain_block`, `admin_delete_domain_block` - thanks catgoat) * Add the stats admin APIs (`admin_measures`, `admin_dimensions`, `admin_retention`) + v1.7.0 ------ * Cleaned code up a bit (thanks eumiro) diff --git a/docs/index.rst b/docs/index.rst index cb4610e..61aa916 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -54,10 +54,11 @@ node running Mastodon by setting `api_base_url` when creating the API object (or creating an app). Mastodon.py aims to implement the complete public Mastodon API. As -of this time, it is feature complete for Mastodon version 3.0.1. Pleroma's -Mastodon API layer, while not an official target, should also be basically +of this time, it is feature complete for Mastodon version 3.5.0. The +Mastodon compatible API layers of various other pieces of software as well +as forks, while not an official target, should also be basically compatible, and Mastodon.py does make some allowances for behaviour that isn't -strictly like that of Mastodon. +strictly like that of Mastodon, and attempts to support extensions to the API. A note about rate limits ------------------------ @@ -376,9 +377,12 @@ Mention dicts 'id': # Mentioned user's (local) account ID } -Scheduled toot dicts -~~~~~~~~~~~~~~~~~~~~ +Scheduled status / toot dicts +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +.. _scheduled status dict: +.. _scheduled status dicts: .. _scheduled toot dict: +.. _scheduled toot dicts: .. code-block:: python @@ -987,7 +991,9 @@ is specified, Mastodon.py defaults to https. .. automethod:: Mastodon.log_in .. _auth_request_url(): .. automethod:: Mastodon.auth_request_url -.. automedhod:: Mastodon.revoke_access_token +.. _set_language(): +.. automethod:: Mastodon.set_language +.. automethod:: Mastodon.revoke_access_token .. automethod:: Mastodon.create_account .. automethod:: Mastodon.email_resend_confirmation diff --git a/mastodon/Mastodon.py b/mastodon/Mastodon.py index 61e7302..c3c02a0 100644 --- a/mastodon/Mastodon.py +++ b/mastodon/Mastodon.py @@ -450,6 +450,7 @@ class Mastodon: with open(self.access_token, 'r') as token_file: self.access_token = token_file.readline().rstrip() + # For newer versions, we also store the URL try_base_url = token_file.readline().rstrip() if try_base_url is not None and len(try_base_url) != 0: try_base_url = Mastodon.__protocolize(try_base_url) @@ -457,6 +458,13 @@ class Mastodon: raise MastodonIllegalArgumentError('Mismatch in base URLs between files and/or specified') self.api_base_url = try_base_url + # For EVEN newer vesions, we ALSO ALSO store the client id and secret so that you don't need to reauth to revoke + try: + self.client_id = token_file.readline().rstrip() + self.client_secret = token_file.readline().rstrip() + except: + pass + # Verify we have a base URL, protocolize if self.api_base_url is None: raise MastodonIllegalArgumentError("API base URL is required.") @@ -611,7 +619,7 @@ class Mastodon: Handles password and OAuth-based authorization. - Will throw a `MastodonIllegalArgumentError` if the OAuth or the + Will throw a `MastodonIllegalArgumentError` if the OAuth flow data or the username / password credentials given are incorrect, and `MastodonAPIError` if all of the requested scopes were not granted. @@ -664,6 +672,8 @@ class Mastodon: with open(to_file, 'w') as token_file: token_file.write(response['access_token'] + "\n") token_file.write(self.api_base_url + "\n") + token_file.write(self.client_id + "\n") + token_file.write(self.client_secret + "\n") self.__logged_in_id = None @@ -1132,7 +1142,7 @@ class Mastodon: * `update` - A status the logged in user has reblogged (and only those, as of 4.0.0) has been edited * `status` - A user that the logged in user has enabned notifications for has enabled `notify` (see `account_follow()`_) * `admin.sign_up` - For accounts with appropriate permissions (TODO: document which those are when adding the permission API): A new user has signed up - * `admin.report ` - For accounts with appropriate permissions (TODO: document which those are when adding the permission API): A new report has been received + * `admin.report` - For accounts with appropriate permissions (TODO: document which those are when adding the permission API): A new report has been received Parameters `exclude_types` and `types` are array of these types, specifying them will in- or exclude the types of notifications given. It is legal to give both parameters at the same tine, the result will then be the intersection of the results of both filters. Specifying `mentions_only` is a deprecated way to set -- cgit v1.2.3