Skip to content

Commit

Permalink
Mastodon: add EXPIRE_APPS_BEFORE, use to update redirect_uris, scopes…
Browse files Browse the repository at this point in the history
…, etc

for snarfed/bridgy#1344
  • Loading branch information
snarfed committed Jan 18, 2023
1 parent fd683e0 commit fd0f316
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
10 changes: 10 additions & 0 deletions oauth_dropins/mastodon.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,13 +192,18 @@ class Start(views.Start):
OAuth callback (aka redirect) URIs in the OAuth app
SCOPE_SEPARATOR: string, used to separate multiple scopes
APP_CLASS: API app datastore class
EXPIRE_APPS_BEFORE: datetime, if the API client app was created before this,
it will be discarded and a new one will be created. Set to the last time
you changed something material about the client, eg redirect URLs or scopes.
"""
NAME = 'mastodon'
LABEL = 'Mastodon'
DEFAULT_SCOPE = 'read:accounts'
REDIRECT_PATHS = ()
SCOPE_SEPARATOR = ' '
APP_CLASS = MastodonApp
# https://github.com/snarfed/bridgy/issues/1344
EXPIRE_APPS_BEFORE = None

def app_name(self):
"""Returns the user-visible name of this application.
Expand Down Expand Up @@ -274,6 +279,11 @@ def redirect_url(self, state=None, instance=None):
# always be localhost
query = query.filter(self.APP_CLASS.app_name == app_name)
app = query.get()

if app and self.EXPIRE_APPS_BEFORE and app.created_at < self.EXPIRE_APPS_BEFORE:
logging.info(f'Creating new client app for {instance} because existing app {app.key} was created before EXPIRE_APPS_BEFORE {self.EXPIRE_APPS_BEFORE}')
app = None

if not app:
app = self._register_app(instance, app_name, app_url)
app.instance_info = resp.text
Expand Down
2 changes: 1 addition & 1 deletion oauth_dropins/webutil
Submodule webutil updated 1 files
+1 −0 tests/__init__.py

0 comments on commit fd0f316

Please sign in to comment.