diff options
author | clarkzjw <[email protected]> | 2023-02-22 16:56:21 -0800 |
---|---|---|
committer | clarkzjw <[email protected]> | 2023-02-23 12:07:32 -0800 |
commit | d469f16670df2d1748a6377d1bebe9b730dc25be (patch) | |
tree | c8b84c1a2f97a5c0170f29e431c54e4b99f8e716 /callback.py | |
parent | 6af01f18c2bb4f641d85d4b3caa00b4e2e842a77 (diff) | |
download | swarm2fediverse-d469f16670df2d1748a6377d1bebe9b730dc25be.tar.gz |
fix oauth login flow
Diffstat (limited to 'callback.py')
-rw-r--r-- | callback.py | 18 |
1 files changed, 13 insertions, 5 deletions
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 * | |||
10 | from dbstore.dbm_store import get_loc | 10 | from dbstore.dbm_store import get_loc |
11 | from foursquare.poi import OSM_ENDPOINT | 11 | from foursquare.poi import OSM_ENDPOINT |
12 | from foursquare.poi import query_poi | 12 | from foursquare.poi import query_poi |
13 | from toot import mastodon_client | 13 | # from toot import mastodon_client |
14 | from config import BOT_SCOPE | ||
15 | |||
16 | mastodon_client = None | ||
14 | 17 | ||
15 | 18 | ||
16 | def generate_toot_text(poi_name, poi_locality, poi_region, poi_lat, poi_lon): | 19 | 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): | |||
59 | 62 | ||
60 | async def callback_generate_fedi_login_url(update: Update, context: ContextTypes.DEFAULT_TYPE) -> int: | 63 | async def callback_generate_fedi_login_url(update: Update, context: ContextTypes.DEFAULT_TYPE) -> int: |
61 | # generate fedi OAuth login url | 64 | # generate fedi OAuth login url |
65 | global mastodon_client | ||
66 | |||
62 | home_instance = update.effective_message.text | 67 | home_instance = update.effective_message.text |
63 | client_id, client_secret = Mastodon.create_app( | 68 | client_id, client_secret = Mastodon.create_app( |
64 | "Checkin.bot", | 69 | "Checkin.bot", |
65 | scopes=['write:media', 'write:statuses'], | 70 | scopes=BOT_SCOPE, |
66 | redirect_uris="{}{}".format(BOT_DOMAIN, FEDI_LOGIN_CALLBACK_URL), | 71 | redirect_uris="{}{}".format(BOT_DOMAIN, FEDI_LOGIN_CALLBACK_URL), |
67 | api_base_url=home_instance, | 72 | api_base_url=home_instance, |
68 | ) | 73 | ) |
69 | mastodon_client = Mastodon(client_id=client_id, client_secret=client_secret, api_base_url=home_instance) | 74 | m = Mastodon(client_id=client_id, client_secret=client_secret, api_base_url=home_instance) |
70 | oauth_url = mastodon_client.auth_request_url(redirect_uris="{}{}".format(BOT_DOMAIN, FEDI_LOGIN_CALLBACK_URL), | 75 | |
71 | scopes=['write:media', 'write:statuses'], | 76 | # TODO |
77 | # generate random string as OAuth state | ||
78 | oauth_url = m.auth_request_url(redirect_uris="{}{}".format(BOT_DOMAIN, FEDI_LOGIN_CALLBACK_URL), | ||
79 | scopes=BOT_SCOPE, | ||
72 | state=update.effective_user.id) | 80 | state=update.effective_user.id) |
73 | 81 | ||
74 | await update.message.reply_text(PROMPT_FEDI_LOGIN, | 82 | await update.message.reply_text(PROMPT_FEDI_LOGIN, |