Skip to content
This repository has been archived by the owner on Apr 27, 2020. It is now read-only.

Latest commit

 

History

History
66 lines (45 loc) · 1.84 KB

README.rst

File metadata and controls

66 lines (45 loc) · 1.84 KB

pyramid_contextauth

https://travis-ci.org/hadrien/pyramid_contextauth.png https://coveralls.io/repos/hadrien/pyramid_contextauth/badge.png https://pypip.in/d/pyramid_contextauth/badge.png

A simple pyramid extension to register contexts based authentication policy. Introspectables for policies registered are added to configuration and will appear in debugtoolbar with their associated contexts.

from pyramid.security import remember, forget
from pyramid.authentication import AuthTktAuthenticationPolicy

def includeme(config):
    config.include('pyramid_contextauth')
    config.register_authentication_policy(
        AuthTktAuthenticationPolicy('secret'),
        Context1,
    )
    config.register_authentication_policy(
        ContextAuthenticationPolicy(),
        (Context2, Context3),
    )


class Context1(object):
    pass


class Context2(object):
    pass


class Context3(object):
    pass


class ContextAuthenticationPolicy(object):

    def authenticated_userid(self, request):
        return unauthenticated_userid(request)

    def unauthenticated_userid(self, request):
        "A dummy example"
        return request.POST.get('userid')

    def effective_principals(self, request):
        if self.unauthenticated_userid(request):
            return ['User']
        return []

    def remember(self, request, prinicpal, **kw):
        return remember(request, prinicpal, **kw)

    def forget(self, request):
        return forget(request)