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 /bot.py | |
parent | 6af01f18c2bb4f641d85d4b3caa00b4e2e842a77 (diff) | |
download | swarm2fediverse-d469f16670df2d1748a6377d1bebe9b730dc25be.tar.gz |
fix oauth login flow
Diffstat (limited to 'bot.py')
-rw-r--r-- | bot.py | 22 |
1 files changed, 20 insertions, 2 deletions
@@ -56,8 +56,11 @@ from config import ( | |||
56 | LOCATION_CONFIRMATION, | 56 | LOCATION_CONFIRMATION, |
57 | ADD_MEDIA, | 57 | ADD_MEDIA, |
58 | ADD_COMMENT, | 58 | ADD_COMMENT, |
59 | BOT_TOKEN | 59 | BOT_TOKEN, |
60 | BOT_SCOPE | ||
60 | ) | 61 | ) |
62 | from mastodon import Mastodon | ||
63 | |||
61 | 64 | ||
62 | # Enable logging | 65 | # Enable logging |
63 | logging.basicConfig( | 66 | logging.basicConfig( |
@@ -85,7 +88,22 @@ class FediLoginCallbackContext(CallbackContext[ExtBot, dict, dict, dict]): | |||
85 | 88 | ||
86 | 89 | ||
87 | async def process_oauth_login_callback(update: FediLoginCallbackUpdate, context: FediLoginCallbackContext) -> None: | 90 | async def process_oauth_login_callback(update: FediLoginCallbackUpdate, context: FediLoginCallbackContext) -> None: |
88 | text = "Login success, your OAuth code is: {}".format(update.code) | 91 | # query client_id and client_secret from in memory database |
92 | client_id = "" | ||
93 | client_secret = "" | ||
94 | home_instance = "" | ||
95 | |||
96 | mastodon_client = Mastodon(client_id=client_id, client_secret=client_secret, api_base_url=home_instance) | ||
97 | access_token = mastodon_client.log_in( | ||
98 | code=update.code, | ||
99 | redirect_uri="{}{}".format(BOT_DOMAIN, FEDI_LOGIN_CALLBACK_URL), | ||
100 | scopes=BOT_SCOPE | ||
101 | ) | ||
102 | |||
103 | # TODO | ||
104 | # save access_token to database | ||
105 | |||
106 | text = "You have successfully logged in to your Mastodon account!" | ||
89 | await context.bot.send_message(chat_id=update.state, text=text) | 107 | await context.bot.send_message(chat_id=update.state, text=text) |
90 | 108 | ||
91 | 109 | ||