diff options
author | clarkzjw <[email protected]> | 2023-02-23 15:38:38 -0800 |
---|---|---|
committer | clarkzjw <[email protected]> | 2023-02-23 15:38:38 -0800 |
commit | 20b8220a12fc92f95ecae267ce4eb5a80584f564 (patch) | |
tree | 1090256b48a76aae7afe2e10b860a02b43790807 /bot.py | |
parent | 31a2d111d1c0ceb2ebfd5bb5daf4ee0ab2de4eb4 (diff) | |
parent | 4cee8500a51aff6d0a445a3a6259cafed92d4845 (diff) | |
download | swarm2fediverse-20b8220a12fc92f95ecae267ce4eb5a80584f564.tar.gz |
Merge branch 'feature/encryption'
- bot: encrypt access_key with cryptography.fernet library
Diffstat (limited to 'bot.py')
-rw-r--r-- | bot.py | 5 |
1 files changed, 3 insertions, 2 deletions
@@ -4,7 +4,7 @@ import asyncio | |||
4 | import logging | 4 | import logging |
5 | from dataclasses import dataclass | 5 | from dataclasses import dataclass |
6 | from http import HTTPStatus | 6 | from http import HTTPStatus |
7 | from config import BOT_TOKEN, TELEGRAM_WEBHOOK_URL, HEALTHCHECK_URL, FEDI_LOGIN_CALLBACK_URL, BOT_DOMAIN, BOT_PORT | 7 | from config import BOT_TOKEN, TELEGRAM_WEBHOOK_URL, HEALTHCHECK_URL, FEDI_LOGIN_CALLBACK_URL, BOT_DOMAIN, BOT_PORT, ENCRYPT_KEY |
8 | import uvicorn | 8 | import uvicorn |
9 | from starlette.applications import Starlette | 9 | from starlette.applications import Starlette |
10 | from starlette.requests import Request | 10 | from starlette.requests import Request |
@@ -61,6 +61,7 @@ from config import ( | |||
61 | from prompt.string import PROMPT_CHOOSE_ACTION | 61 | from prompt.string import PROMPT_CHOOSE_ACTION |
62 | from mastodon import Mastodon | 62 | from mastodon import Mastodon |
63 | from dbstore.peewee_store import db, User, get_user_by_state | 63 | from dbstore.peewee_store import db, User, get_user_by_state |
64 | from util import encrypt, decrypt | ||
64 | 65 | ||
65 | logging.basicConfig( | 66 | logging.basicConfig( |
66 | format="%(asctime)s - %(name)s - %(levelname)s - %(message)s", level=logging.INFO | 67 | format="%(asctime)s - %(name)s - %(levelname)s - %(message)s", level=logging.INFO |
@@ -104,7 +105,7 @@ async def process_oauth_login_callback(update: FediLoginCallbackUpdate, context: | |||
104 | redirect_uri="{}{}".format(BOT_DOMAIN, FEDI_LOGIN_CALLBACK_URL), | 105 | redirect_uri="{}{}".format(BOT_DOMAIN, FEDI_LOGIN_CALLBACK_URL), |
105 | scopes=BOT_SCOPE | 106 | scopes=BOT_SCOPE |
106 | ) | 107 | ) |
107 | user.access_key = access_token | 108 | user.access_key = encrypt(access_token, ENCRYPT_KEY) |
108 | user.save() | 109 | user.save() |
109 | 110 | ||
110 | text = "You have successfully logged in to your Mastodon account!" | 111 | text = "You have successfully logged in to your Mastodon account!" |