当前位置: 首页>>代码示例>>Python>>正文


Python cookie_storage.EncryptedCookieStorage方法代码示例

本文整理汇总了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 
开发者ID:aio-libs,项目名称:aiohttp-security,代码行数:18,代码来源:main.py

示例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 
开发者ID:aio-libs,项目名称:aiohttp-devtools,代码行数:22,代码来源:main.py

示例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)) 
开发者ID:mitre,项目名称:caldera,代码行数:14,代码来源:auth_svc.py

示例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 
开发者ID:aio-libs,项目名称:aiohttp-session,代码行数:12,代码来源:login_required_example.py

示例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 
开发者ID:aio-libs,项目名称:aiohttp-session,代码行数:10,代码来源:main.py

示例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 
开发者ID:aio-libs,项目名称:aiohttp-session,代码行数:13,代码来源:flash_messages_example.py

示例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 
开发者ID:aio-libs,项目名称:aiohttp-session,代码行数:7,代码来源:test_encrypted_cookie_storage.py

示例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 
开发者ID:aio-libs,项目名称:aiohttp-session,代码行数:5,代码来源:test_encrypted_cookie_storage.py

示例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() 
开发者ID:AvaCity,项目名称:avacity-2.0,代码行数:15,代码来源:web.py

示例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 
开发者ID:imbolc,项目名称:aiohttp-login,代码行数:17,代码来源:app.py

示例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>" 
开发者ID:neolynx,项目名称:cirrina,代码行数:56,代码来源:server.py


注:本文中的aiohttp_session.cookie_storage.EncryptedCookieStorage方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。