本文整理汇总了Python中aiohttp_session.cookie_storage.EncryptedCookieStorage方法的典型用法代码示例。如果您正苦于以下问题:Python cookie_storage.EncryptedCookieStorage方法的具体用法?Python cookie_storage.EncryptedCookieStorage怎么用?Python cookie_storage.EncryptedCookieStorage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类aiohttp_session.cookie_storage
的用法示例。
在下文中一共展示了cookie_storage.EncryptedCookieStorage方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: make_app
# 需要导入模块: from aiohttp_session import cookie_storage [as 别名]
# 或者: from aiohttp_session.cookie_storage import EncryptedCookieStorage [as 别名]
def make_app():
app = web.Application()
app.user_map = user_map
configure_handlers(app)
# secret_key must be 32 url-safe base64-encoded bytes
fernet_key = fernet.Fernet.generate_key()
secret_key = base64.urlsafe_b64decode(fernet_key)
storage = EncryptedCookieStorage(secret_key, cookie_name='API_SESSION')
setup_session(app, storage)
policy = SessionIdentityPolicy()
setup_security(app, policy, DictionaryAuthorizationPolicy(user_map))
return app
示例2: create_app
# 需要导入模块: from aiohttp_session import cookie_storage [as 别名]
# 或者: from aiohttp_session.cookie_storage import EncryptedCookieStorage [as 别名]
def create_app():
app = web.Application()
settings = Settings()
app.update(
settings=settings,
static_root_url='/static/',
)
jinja2_loader = jinja2.FileSystemLoader(str(THIS_DIR / 'templates'))
aiohttp_jinja2.setup(app, loader=jinja2_loader)
app.on_startup.append(startup)
app.on_cleanup.append(cleanup)
aiohttp_session.setup(app, EncryptedCookieStorage(settings.auth_key, cookie_name=settings.cookie_name))
app.router.add_get('/', index, name='index')
app.router.add_route('*', '/messages', messages, name='messages')
app.router.add_get('/messages/data', message_data, name='message-data')
return app
示例3: apply
# 需要导入模块: from aiohttp_session import cookie_storage [as 别名]
# 或者: from aiohttp_session.cookie_storage import EncryptedCookieStorage [as 别名]
def apply(self, app, users):
for group, u in users.items():
self.log.debug('Created authentication group: %s' % group)
for k, v in u.items():
self.user_map[k] = self.User(k, v, (group, 'app'), )
app.user_map = self.user_map
fernet_key = fernet.Fernet.generate_key()
secret_key = base64.urlsafe_b64decode(fernet_key)
storage = EncryptedCookieStorage(secret_key, cookie_name='API_SESSION')
setup_session(app, storage)
policy = SessionIdentityPolicy()
setup_security(app, policy, DictionaryAuthorizationPolicy(self.user_map))
示例4: make_app
# 需要导入模块: from aiohttp_session import cookie_storage [as 别名]
# 或者: from aiohttp_session.cookie_storage import EncryptedCookieStorage [as 别名]
def make_app():
app = web.Application()
# secret_key must be 32 url-safe base64-encoded bytes
fernet_key = fernet.Fernet.generate_key()
secret_key = base64.urlsafe_b64decode(fernet_key)
setup(app, EncryptedCookieStorage(secret_key))
app.router.add_get('/', handler, name='restricted')
app.router.add_get('/login', login_page, name='login')
app.router.add_post('/login', login)
return app
示例5: make_app
# 需要导入模块: from aiohttp_session import cookie_storage [as 别名]
# 或者: from aiohttp_session.cookie_storage import EncryptedCookieStorage [as 别名]
def make_app():
app = web.Application()
# secret_key must be 32 url-safe base64-encoded bytes
fernet_key = fernet.Fernet.generate_key()
secret_key = base64.urlsafe_b64decode(fernet_key)
setup(app, EncryptedCookieStorage(secret_key))
app.router.add_get('/', handler)
return app
示例6: make_app
# 需要导入模块: from aiohttp_session import cookie_storage [as 别名]
# 或者: from aiohttp_session.cookie_storage import EncryptedCookieStorage [as 别名]
def make_app():
app = web.Application()
# secret_key must be 32 url-safe base64-encoded bytes
fernet_key = fernet.Fernet.generate_key()
secret_key = base64.urlsafe_b64decode(fernet_key)
setup(app, EncryptedCookieStorage(secret_key))
app.router.add_get('/', handler)
app.router.add_get('/flash', flash_handler)
# Install flash middleware
app.middlewares.append(flash_middleware)
return app
示例7: create_app
# 需要导入模块: from aiohttp_session import cookie_storage [as 别名]
# 或者: from aiohttp_session.cookie_storage import EncryptedCookieStorage [as 别名]
def create_app(handler, key):
middleware = session_middleware(EncryptedCookieStorage(key))
app = web.Application(middlewares=[middleware])
app.router.add_route('GET', '/', handler)
return app
示例8: test_invalid_key
# 需要导入模块: from aiohttp_session import cookie_storage [as 别名]
# 或者: from aiohttp_session.cookie_storage import EncryptedCookieStorage [as 别名]
def test_invalid_key():
with pytest.raises(ValueError):
EncryptedCookieStorage(b'123') # short key
示例9: main
# 需要导入模块: from aiohttp_session import cookie_storage [as 别名]
# 或者: from aiohttp_session.cookie_storage import EncryptedCookieStorage [as 别名]
def main():
global app
app = web.Application()
app.add_routes(routes)
app["redis"] = redis.Redis(decode_responses=True)
fernet_key = fernet.Fernet.generate_key()
secret_key = base64.urlsafe_b64decode(fernet_key)
aiohttp_session.setup(app, EncryptedCookieStorage(secret_key))
aiohttp_jinja2.setup(app, loader=jinja2.FileSystemLoader("templates"))
runner = web.AppRunner(app)
await runner.setup()
site = web.TCPSite(runner, "0.0.0.0", int(config["webserver"]["web_port"]))
await site.start()
示例10: create_app
# 需要导入模块: from aiohttp_session import cookie_storage [as 别名]
# 或者: from aiohttp_session.cookie_storage import EncryptedCookieStorage [as 别名]
def create_app(loop):
app = web.Application(loop=loop, debug=settings.DEBUG)
setup_jinja(app, settings.DEBUG)
aiohttp_session.setup(app, EncryptedCookieStorage(
settings.SESSION_SECRET.encode('utf-8'),
max_age=settings.SESSION_MAX_AGE))
app.middlewares.append(aiohttp_login.flash.middleware)
app.router.add_get('/', handlers.index)
app.router.add_get('/users/', handlers.users, name='users')
app['db'] = await asyncpg.create_pool(dsn=settings.DATABASE, loop=loop)
aiohttp_login.setup(app, AsyncpgStorage(app['db']), settings.AUTH)
return app
示例11: __init__
# 需要导入模块: from aiohttp_session import cookie_storage [as 别名]
# 或者: from aiohttp_session.cookie_storage import EncryptedCookieStorage [as 别名]
def __init__(self, loop=None, login_url="/login", logout_url="/logout"):
if loop is None:
loop = asyncio.get_event_loop()
#: Holds the asyncio event loop which is used to handle requests.
self.loop = loop
# remember the login/logout urls
self.login_url = login_url
self.logout_url = logout_url
#: Holds the aiohttp web application instance.
self.app = web.Application(loop=self.loop) #, middlewares=[session_middleware])
# executor for threaded http requests
self.executor = futures.ThreadPoolExecutor()
#: Holds the asyncio server instance.
self.srv = None
#: Holds all websocket handler information.
self.websockets = {}
#: Holds all registered RPC methods.
self.rpc_methods = {}
# setup cookie encryption for user sessions.
fernet_key = fernet.Fernet.generate_key()
secret_key = base64.urlsafe_b64decode(fernet_key)
setup(self.app, EncryptedCookieStorage(secret_key))
#: Holds authentication functions
self.auth_handlers = []
#: Holds functions which are called upon logout
self.logout_handlers = []
#: Holds functions which are called on startup
self.startup_handlers = []
#: Holds functions which are called on shutdown
self.shutdown_handlers = []
self.create_context_func = None
self.destroy_context_func = None
# add default routes to request handler.
self.http_post(self.login_url)(self._login)
self.http_post(self.logout_url)(self._logout)
self.logger = logging.getLogger(__name__) # pylint: disable=invalid-name
# swagger documentation
self.title = "Cirrina based web application"
self.description = """Cirrina is a web application framework using aiohttp.
See https://github.com/neolynx/cirrina."""
self.api_version = "0.1"
self.contact = "André Roth <neolynx@gmail.com>"