aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorclarkzjw <[email protected]>2023-02-23 15:38:38 -0800
committerclarkzjw <[email protected]>2023-02-23 15:38:38 -0800
commit20b8220a12fc92f95ecae267ce4eb5a80584f564 (patch)
tree1090256b48a76aae7afe2e10b860a02b43790807 /callback.py
parent31a2d111d1c0ceb2ebfd5bb5daf4ee0ab2de4eb4 (diff)
parent4cee8500a51aff6d0a445a3a6259cafed92d4845 (diff)
downloadswarm2fediverse-20b8220a12fc92f95ecae267ce4eb5a80584f564.tar.gz
Merge branch 'feature/encryption'
- bot: encrypt access_key with cryptography.fernet library
Diffstat (limited to 'callback.py')
-rw-r--r--callback.py22
1 files changed, 11 insertions, 11 deletions
diff --git a/callback.py b/callback.py
index d968523..a1b4b2d 100644
--- a/callback.py
+++ b/callback.py
@@ -9,10 +9,11 @@ from command import *
9from dbstore.peewee_store import get_poi_by_fsq_id 9from dbstore.peewee_store import get_poi_by_fsq_id
10from foursquare.poi import OSM_ENDPOINT 10from foursquare.poi import OSM_ENDPOINT
11from foursquare.poi import query_poi 11from foursquare.poi import query_poi
12from config import BOT_SCOPE 12from config import BOT_SCOPE, ENCRYPT_KEY
13from dbstore.peewee_store import User, db, TOOT_VISIBILITY_PRIVATE, TOOT_VISIBILITY_PUBLIC, TOOT_VISIBILITY_UNLISTED 13from dbstore.peewee_store import User, db, TOOT_VISIBILITY_PRIVATE, TOOT_VISIBILITY_PUBLIC, TOOT_VISIBILITY_UNLISTED
14import uuid 14import uuid
15from mastodon import Mastodon 15from mastodon import Mastodon
16from util import decrypt
16 17
17 18
18def generate_uuid(): 19def generate_uuid():
@@ -23,7 +24,7 @@ def get_mastodon_client(user_id: int):
23 with db.connection_context(): 24 with db.connection_context():
24 user = User.get(User.telegram_user_id == user_id) 25 user = User.get(User.telegram_user_id == user_id)
25 if user.home_instance and user.access_key: 26 if user.home_instance and user.access_key:
26 return Mastodon(access_token=user.access_key, api_base_url=user.home_instance) 27 return Mastodon(access_token=decrypt(user.access_key, ENCRYPT_KEY), api_base_url=user.home_instance)
27 28
28 29
29def generate_toot_text(poi_name, poi_locality, poi_region, poi_lat, poi_lon): 30def generate_toot_text(poi_name, poi_locality, poi_region, poi_lat, poi_lon):
@@ -85,21 +86,20 @@ async def callback_generate_fedi_login_url(update: Update, context: ContextTypes
85 user_id = update.effective_user.id 86 user_id = update.effective_user.id
86 state = generate_uuid() 87 state = generate_uuid()
87 88
88 db.connect() 89 with db.connection_context():
89 u = User.get_or_none(telegram_user_id=user_id) 90 u = User.get_or_none(telegram_user_id=user_id)
90 if u is None: 91 if u is None:
91 u = User.create(telegram_user_id=user_id, access_key="", home_instance=home_instance, 92 u = User.create(telegram_user_id=user_id, access_key="", home_instance=home_instance,
92 client_id=client_id, client_secret=client_secret, state=state) 93 client_id=client_id, client_secret=client_secret, state=state)
93 u.save() 94 u.save()
94 db.close()
95 95
96 oauth_url = m.auth_request_url(redirect_uris="{}{}".format(BOT_DOMAIN, FEDI_LOGIN_CALLBACK_URL), 96 oauth_url = m.auth_request_url(redirect_uris="{}{}".format(BOT_DOMAIN, FEDI_LOGIN_CALLBACK_URL),
97 scopes=BOT_SCOPE, 97 scopes=BOT_SCOPE,
98 state=state) 98 state=state)
99 99
100 msg = await update.message.reply_text(PROMPT_FEDI_LOGIN, 100 msg = await update.message.reply_text(PROMPT_FEDI_LOGIN,
101 reply_markup=InlineKeyboardMarkup([[InlineKeyboardButton("Login", url=oauth_url)]]), 101 reply_markup=InlineKeyboardMarkup([[InlineKeyboardButton("Login", url=oauth_url)]]),
102 parse_mode=ParseMode.MARKDOWN) 102 parse_mode=ParseMode.MARKDOWN)
103 103
104 context.user_data[PROMPT_FEDI_LOGIN] = msg.message_id 104 context.user_data[PROMPT_FEDI_LOGIN] = msg.message_id
105 return FEDI_LOGIN 105 return FEDI_LOGIN
Powered by cgit v1.2.3 (git 2.41.0)