From 6af01f18c2bb4f641d85d4b3caa00b4e2e842a77 Mon Sep 17 00:00:00 2001 From: clarkzjw Date: Wed, 22 Feb 2023 15:57:02 -0800 Subject: create oauth app before user login --- bot.py | 5 +---- callback.py | 8 +++++++- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/bot.py b/bot.py index 6198bc4..3b45906 100644 --- a/bot.py +++ b/bot.py @@ -85,10 +85,7 @@ class FediLoginCallbackContext(CallbackContext[ExtBot, dict, dict, dict]): async def process_oauth_login_callback(update: FediLoginCallbackUpdate, context: FediLoginCallbackContext) -> None: - combined_payloads = update.code - text = "Login success, your code is: {}".format(combined_payloads) - print(text) - print(update.state) + text = "Login success, your OAuth code is: {}".format(update.code) await context.bot.send_message(chat_id=update.state, text=text) diff --git a/callback.py b/callback.py index e7a8308..d2f3ae7 100644 --- a/callback.py +++ b/callback.py @@ -60,7 +60,13 @@ async def process_media_group(context: CallbackContext): async def callback_generate_fedi_login_url(update: Update, context: ContextTypes.DEFAULT_TYPE) -> int: # generate fedi OAuth login url home_instance = update.effective_message.text - mastodon_client = Mastodon(client_id=MASTODON_CLIENT_ID_FILE, api_base_url=home_instance) + client_id, client_secret = Mastodon.create_app( + "Checkin.bot", + scopes=['write:media', 'write:statuses'], + redirect_uris="{}{}".format(BOT_DOMAIN, FEDI_LOGIN_CALLBACK_URL), + api_base_url=home_instance, + ) + mastodon_client = Mastodon(client_id=client_id, client_secret=client_secret, api_base_url=home_instance) oauth_url = mastodon_client.auth_request_url(redirect_uris="{}{}".format(BOT_DOMAIN, FEDI_LOGIN_CALLBACK_URL), scopes=['write:media', 'write:statuses'], state=update.effective_user.id) -- cgit v1.2.3