From d469f16670df2d1748a6377d1bebe9b730dc25be Mon Sep 17 00:00:00 2001 From: clarkzjw Date: Wed, 22 Feb 2023 16:56:21 -0800 Subject: fix oauth login flow --- callback.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'callback.py') diff --git a/callback.py b/callback.py index d2f3ae7..c7cb60c 100644 --- a/callback.py +++ b/callback.py @@ -10,7 +10,10 @@ from command import * from dbstore.dbm_store import get_loc from foursquare.poi import OSM_ENDPOINT from foursquare.poi import query_poi -from toot import mastodon_client +# from toot import mastodon_client +from config import BOT_SCOPE + +mastodon_client = None def generate_toot_text(poi_name, poi_locality, poi_region, poi_lat, poi_lon): @@ -59,16 +62,21 @@ 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 + global mastodon_client + home_instance = update.effective_message.text client_id, client_secret = Mastodon.create_app( "Checkin.bot", - scopes=['write:media', 'write:statuses'], + scopes=BOT_SCOPE, 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'], + m = Mastodon(client_id=client_id, client_secret=client_secret, api_base_url=home_instance) + + # TODO + # generate random string as OAuth state + oauth_url = m.auth_request_url(redirect_uris="{}{}".format(BOT_DOMAIN, FEDI_LOGIN_CALLBACK_URL), + scopes=BOT_SCOPE, state=update.effective_user.id) await update.message.reply_text(PROMPT_FEDI_LOGIN, -- cgit v1.2.3