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


Python authentication.AuthTktAuthenticationPolicy方法代码示例

本文整理汇总了Python中pyramid.authentication.AuthTktAuthenticationPolicy方法的典型用法代码示例。如果您正苦于以下问题:Python authentication.AuthTktAuthenticationPolicy方法的具体用法?Python authentication.AuthTktAuthenticationPolicy怎么用?Python authentication.AuthTktAuthenticationPolicy使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyramid.authentication的用法示例。


在下文中一共展示了authentication.AuthTktAuthenticationPolicy方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: from pyramid import authentication [as 别名]
# 或者: from pyramid.authentication import AuthTktAuthenticationPolicy [as 别名]
def main(global_config, **settings):
    """ This function returns a Pyramid WSGI application.
    """
    engine = engine_from_config(settings, 'sqlalchemy.')
    DBSession.configure(bind=engine)
    Base.metadata.bind = engine

    authn_policy = AuthTktAuthenticationPolicy(
        'secret', callback=groupfinder, hashalg='sha512'
    )
    authz_policy = ACLAuthorizationPolicy()

    config = Configurator(settings=settings, root_factory='myshop.RootFactory')
    config.set_authentication_policy(authn_policy)
    config.set_authorization_policy(authz_policy)

    config.set_request_property(get_user, 'user', reify=True)
    config.set_request_property(lambda request: DBSession, 'db', reify=True)

    config.include('pyramid_chameleon')

    config.add_static_view('static', 'static', cache_max_age=3600)
    config.add_route('home', '/')
    config.add_route('category', '/category/{id}')
    config.add_route('item', '/item/{id}')
    config.add_route('search', '/search')
    config.add_route('annoncement', '/annoncement/{id}')

    config.add_route('login', '/login')
    config.add_route('logout', '/logout')
    config.add_route('register', '/register')

    config.add_route('order', '/order')
    config.add_route('cart', '/cart')
    config.add_route('comment', '/comment')

    config.add_route('add_item', '/category/{id}/add')

    config.scan()
    return config.make_wsgi_app() 
开发者ID:Akagi201,项目名称:learning-python,代码行数:42,代码来源:__init__.py

示例2: __init__

# 需要导入模块: from pyramid import authentication [as 别名]
# 或者: from pyramid.authentication import AuthTktAuthenticationPolicy [as 别名]
def __init__(self, settings):
        self._auth_tkt_policy = AuthTktAuthenticationPolicy(secret=make_hex_id(),
                                                            hashalg='sha384',
                                                            secure=False) 
开发者ID:CERT-Polska,项目名称:n6,代码行数:6,代码来源:_pyramid_commons.py

示例3: make_app

# 需要导入模块: from pyramid import authentication [as 别名]
# 或者: from pyramid.authentication import AuthTktAuthenticationPolicy [as 别名]
def make_app(server_config):
    config = Configurator(
        settings=server_config, root_factory=APIFactory, default_permission="access"
    )
    config.include("pyramid_jinja2")
    module_, class_ = server_config["signature_checker"].rsplit(".", maxsplit=1)
    signature_checker_cls = getattr(importlib.import_module(module_), class_)
    config.registry.signature_checker = signature_checker_cls(server_config["secret"])
    authn_policy = AuthTktAuthenticationPolicy(
        server_config["cookie_secret"], max_age=2592000
    )
    authz_policy = ACLAuthorizationPolicy()

    config.set_authentication_policy(authn_policy)
    config.set_authorization_policy(authz_policy)

    json_renderer = JSON(serializer=json.dumps, indent=4)
    json_renderer.add_adapter(datetime.datetime, datetime_adapter)
    json_renderer.add_adapter(uuid.UUID, uuid_adapter)
    config.add_renderer("json", json_renderer)

    config.add_subscriber(
        "channelstream.subscribers.handle_new_request", "pyramid.events.NewRequest"
    )
    config.add_request_method("channelstream.utils.handle_cors", "handle_cors")
    config.include("channelstream.wsgi_views")
    config.scan("channelstream.wsgi_views.server")
    config.scan("channelstream.wsgi_views.error_handlers")
    config.scan("channelstream.events")

    config.include("pyramid_apispec.views")
    config.pyramid_apispec_add_explorer(
        spec_route_name="openapi_spec",
        script_generator="channelstream.utils:swagger_ui_script_template",
        permission="admin",
        route_args={
            "factory": "channelstream.wsgi_views.wsgi_security:AdminAuthFactory"
        },
    )
    app = config.make_wsgi_app()
    return app 
开发者ID:Channelstream,项目名称:channelstream,代码行数:43,代码来源:wsgi_app.py

示例4: test_secured_default_view_not_allowed

# 需要导入模块: from pyramid import authentication [as 别名]
# 或者: from pyramid.authentication import AuthTktAuthenticationPolicy [as 别名]
def test_secured_default_view_not_allowed():
    config = Configurator()
    config.set_authentication_policy(AuthTktAuthenticationPolicy('seekrit'))
    config.set_authorization_policy(ACLAuthorizationPolicy())
    config.scan('resource_abc')
    app = make_app(config)
    app.get('/secure', status=403) 
开发者ID:wichert,项目名称:rest_toolkit,代码行数:9,代码来源:test_resource.py

示例5: main

# 需要导入模块: from pyramid import authentication [as 别名]
# 或者: from pyramid.authentication import AuthTktAuthenticationPolicy [as 别名]
def main(global_config, **settings):
    """ This function returns a Pyramid WSGI application.
    """
    engine = engine_from_config(settings, 'sqlalchemy.')
    DBSession.configure(bind=engine)
    Base.metadata.bind = engine
    session_factory = session_factory_from_settings(settings)
    authentication = AuthTktAuthenticationPolicy(
        settings.get('session.secret'),
    )
    authorization = ACLAuthorizationPolicy()

    config = Configurator(
        settings=settings,
        root_factory=root_factory,
        authentication_policy=authentication,
        authorization_policy=authorization,
        session_factory=session_factory,
    )
    config.add_translation_dirs(
        'colander:locale/',
        'travelcrm:locale/',
    )
    config.add_subscriber(
        '.lib.subscribers.company_schema',
        'pyramid.events.NewRequest'
    )
    config.add_subscriber(
        '.lib.subscribers.company_settings',
        'pyramid.events.NewRequest'
    )
    config.add_subscriber(
        '.lib.subscribers.helpers',
        'pyramid.events.BeforeRender'
    )
    config.add_subscriber(
        '.lib.subscribers.scheduler',
        'pyramid.events.ApplicationCreated'
    )

    config.add_renderer('sse', SSERendererFactory)
    config.add_renderer('str', STRRendererFactory)
    config.add_static_view('css', 'static/css', cache_max_age=3600)
    config.add_static_view('js', 'static/js', cache_max_age=3600)
    config.add_thumb_view('thumbs')

    config.scan()
    return config.make_wsgi_app() 
开发者ID:mazvv,项目名称:travelcrm,代码行数:50,代码来源:__init__.py

示例6: _setup_ticket_policy

# 需要导入模块: from pyramid import authentication [as 别名]
# 或者: from pyramid.authentication import AuthTktAuthenticationPolicy [as 别名]
def _setup_ticket_policy(config, params):
    """ Setup Pyramid AuthTktAuthenticationPolicy.

    Notes:
      * Initial `secret` params value is considered to be a name of config
        param that represents a cookie name.
      * `auth_model.get_groups_by_userid` is used as a `callback`.
      * Also connects basic routes to perform authentication actions.

    :param config: Pyramid Configurator instance.
    :param params: Nefertari dictset which contains security scheme
        `settings`.
    """
    from nefertari.authentication.views import (
        TicketAuthRegisterView, TicketAuthLoginView,
        TicketAuthLogoutView)

    log.info('Configuring Pyramid Ticket Authn policy')
    if 'secret' not in params:
        raise ValueError(
            'Missing required security scheme settings: secret')
    params['secret'] = config.registry.settings[params['secret']]

    auth_model = config.registry.auth_model
    params['callback'] = auth_model.get_groups_by_userid

    config.add_request_method(
        auth_model.get_authuser_by_userid, 'user', reify=True)

    policy = AuthTktAuthenticationPolicy(**params)

    RegisterViewBase = TicketAuthRegisterView
    if config.registry.database_acls:
        class RegisterViewBase(ACLAssignRegisterMixin,
                               TicketAuthRegisterView):
            pass

    class RamsesTicketAuthRegisterView(RegisterViewBase):
        Model = config.registry.auth_model

    class RamsesTicketAuthLoginView(TicketAuthLoginView):
        Model = config.registry.auth_model

    class RamsesTicketAuthLogoutView(TicketAuthLogoutView):
        Model = config.registry.auth_model

    common_kw = {
        'prefix': 'auth',
        'factory': 'nefertari.acl.AuthenticationACL',
    }

    root = config.get_root_resource()
    root.add('register', view=RamsesTicketAuthRegisterView, **common_kw)
    root.add('login', view=RamsesTicketAuthLoginView, **common_kw)
    root.add('logout', view=RamsesTicketAuthLogoutView, **common_kw)

    return policy 
开发者ID:ramses-tech,项目名称:ramses,代码行数:59,代码来源:auth.py


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