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 os import urandom
from aiohttp import web from aiohttp import web
import aiohttp_session import aiohttp_session
import aioredis
import base64 import base64
from aiohttp_session import get_session, session_middleware from aiohttp_session import get_session, session_middleware
from aiohttp_session.cookie_storage import EncryptedCookieStorage from aiohttp_session.cookie_storage import EncryptedCookieStorage
from aiohttp_session.redis_storage import RedisStorage
from appPublic.jsonConfig import getConfig from appPublic.jsonConfig import getConfig
from appPublic.rsawrap import RSA from appPublic.rsawrap import RSA
from appPublic.app_logger import AppLogger from appPublic.app_logger import AppLogger
class AuthAPI(AppLogger): class AuthAPI(AppLogger):
def __init__(self): def __init__(self):
super().__init__() super().__init__()
@ -34,7 +37,15 @@ class AuthAPI(AppLogger):
def setupAuth(self,app): def setupAuth(self,app):
# setup session middleware in aiohttp fashion # setup session middleware in aiohttp fashion
storage = EncryptedCookieStorage(urandom(32)) 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) aiohttp_session.setup(app, storage)
# Create an auth ticket mechanism that expires after 1 minute (60 # Create an auth ticket mechanism that expires after 1 minute (60

View File

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

View File

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