Пример #1
0
class Pi(object):

    app = Klein()

    def __init__(self, audience):
        self.authenticator = Authenticator(audience=audience)

    @app.route("/auth/login", methods=["POST"])
    def login(self, request):
        assertion = request.args.get("assertion")
        try:
            response = self.authenticator.authenticate(assertion=assertion)
        except AuthenticationError:
            request.setResponseCode(204)
            return
        else:
            response.addCallback(IPersona(request.getSession()).success)

    @app.route("/auth/logout", methods=["POST"])
    def logout(self, request):
        request.getSession().expire()

    @app.route("/auth/status")
    def status(self, request):
        email = IPersona(request.getSession()).email
        if email is not None:
            return email
        request.setResponseCode(401)

    @app.route("/")
    @app.route("/static", branch=True)
    def index(self, request):
        return File(STATIC_DIR.path)
Пример #2
0
 def __init__(self, audience):
     self.authenticator = Authenticator(audience=audience)