aboutsummaryrefslogtreecommitdiff
path: root/bot.py
diff options
context:
space:
mode:
authorclarkzjw <[email protected]>2023-02-23 15:37:48 -0800
committerclarkzjw <[email protected]>2023-02-23 15:37:48 -0800
commit4cee8500a51aff6d0a445a3a6259cafed92d4845 (patch)
tree1090256b48a76aae7afe2e10b860a02b43790807 /bot.py
parent31a2d111d1c0ceb2ebfd5bb5daf4ee0ab2de4eb4 (diff)
downloadswarm2fediverse-4cee8500a51aff6d0a445a3a6259cafed92d4845.tar.gz
bot: encrypt access_key with cryptography.fernet library
Diffstat (limited to 'bot.py')
-rw-r--r--bot.py5
1 files changed, 3 insertions, 2 deletions
diff --git a/bot.py b/bot.py
index 45b2af7..7d10ddd 100644
--- a/bot.py
+++ b/bot.py
@@ -4,7 +4,7 @@ import asyncio
4import logging 4import logging
5from dataclasses import dataclass 5from dataclasses import dataclass
6from http import HTTPStatus 6from http import HTTPStatus
7from config import BOT_TOKEN, TELEGRAM_WEBHOOK_URL, HEALTHCHECK_URL, FEDI_LOGIN_CALLBACK_URL, BOT_DOMAIN, BOT_PORT 7from config import BOT_TOKEN, TELEGRAM_WEBHOOK_URL, HEALTHCHECK_URL, FEDI_LOGIN_CALLBACK_URL, BOT_DOMAIN, BOT_PORT, ENCRYPT_KEY
8import uvicorn 8import uvicorn
9from starlette.applications import Starlette 9from starlette.applications import Starlette
10from starlette.requests import Request 10from starlette.requests import Request
@@ -61,6 +61,7 @@ from config import (
61from prompt.string import PROMPT_CHOOSE_ACTION 61from prompt.string import PROMPT_CHOOSE_ACTION
62from mastodon import Mastodon 62from mastodon import Mastodon
63from dbstore.peewee_store import db, User, get_user_by_state 63from dbstore.peewee_store import db, User, get_user_by_state
64from util import encrypt, decrypt
64 65
65logging.basicConfig( 66logging.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!"
Powered by cgit v1.2.3 (git 2.41.0)