當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。