This commit is contained in:
yumoqing 2023-07-18 18:25:59 +08:00
parent 6047f26de3
commit 48a8a33fab
3 changed files with 20 additions and 5 deletions

View File

@ -4,14 +4,17 @@ from aiohttp_auth.auth.ticket_auth import TktAuthentication
from os import urandom
from aiohttp import web
import aiohttp_session
import aioredis
import base64
from aiohttp_session import get_session, session_middleware
from aiohttp_session.cookie_storage import EncryptedCookieStorage
from aiohttp_session.redis_storage import RedisStorage
from appPublic.jsonConfig import getConfig
from appPublic.rsawrap import RSA
from appPublic.app_logger import AppLogger
class AuthAPI(AppLogger):
def __init__(self):
super().__init__()
@ -34,7 +37,15 @@ class AuthAPI(AppLogger):
def setupAuth(self,app):
# setup session middleware in aiohttp fashion
storage = EncryptedCookieStorage(urandom(32))
"""
if self.conf.website.session_redis:
url = self.conf.website.session_redis.url
# redis = await aioredis.from_url("redis://127.0.0.1:6379")
redis = await aioredis.from_url(url)
storage = aiohttp_session.redis_storage.RedisStorage(redis)
"""
aiohttp_session.setup(app, storage)
# Create an auth ticket mechanism that expires after 1 minute (60

View File

@ -19,10 +19,13 @@ from .filestorage import TmpFileRecord
class ConfiguredServer(AppLogger):
def __init__(self, auth_klass=AuthAPI, workdir=None):
self.auth_klass = auth_klass
self.workdir = workdir
super().__init__()
if workdir is not None:
if self.workdir is not None:
pp = ProgramPath()
config = getConfig(workdir,{'workdir':workdir,'ProgramPath':pp})
config = getConfig(self.workdir,
{'workdir':self.workdir,'ProgramPath':pp})
else:
config = getConfig()
if config.databases:
@ -35,11 +38,11 @@ class ConfiguredServer(AppLogger):
print(f'{client_max_size=}')
self.app = web.Application(client_max_size=client_max_size)
auth = auth_klass()
auth.setupAuth(self.app)
self.configPath(config)
def run(self):
auth = self.auth_klass()
await auth.setupAuth(self.app)
self.configPath(config)
a = TmpFileRecord()
config = getConfig()
ssl_context = None

View File

@ -6,6 +6,7 @@ aiohttp
aiohttp_session
aiohttp_auth_autz
aiomysql
aioredis
psycopg2-binary
aiopg
jinja2