How to use the klein.Authorization function in klein

To help you get started, we’ve selected a few klein examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github twisted / klein / loginspike.py View on Github external
@requirer.require(style.renderMethod, account=Authorization(ISimpleAccount))
def username(tag, account):
    # type: (Tag, ISimpleAccount) -> Tag
    return tag(account.username)
github twisted / klein / loginspike.py View on Github external
    binding=Authorization(ISimpleAccountBinding, required=False),
    session=RequestComponent(ISession),
)
@inlineCallbacks
def sessions(binding, form, session):
    # type: (ISimpleAccountBinding, Form, ISession) -> Deferred
    if binding is None:
        returnValue({"sessions": []})
    else:
        dump = {
            "sessions": [
                oneSession.widget(
                    session_info, form, session.identifier == session_info.id
                )
                for session_info in (yield binding.boundSessionInformation())
            ]
        }
github twisted / klein / loginspike.py View on Github external
    reader=Authorization(ChirpReader)
)
@inlineCallbacks
def readSomeChirps(user, reader):
    # type: (str, ChirpReader) -> Deferred
    chirps = yield reader.readChirps(user)
    returnValue({
        "user": user,
        "chirps": chirps,
    })
github twisted / klein / loginspike.py View on Github external
    account=Authorization(ISimpleAccount, required=False),
    chirp_form=Form.rendererFor(addChirp, "/chirp")
)
def root(chirp_form, account):
    # type: (Chirper, ISimpleAccount) -> Dict
    return {
        "result": "hello world",
        "homeActive": "active",
        "chirp_form": chirp_form if account is not None else u"",
    }
github twisted / klein / loginspike.py View on Github external
    chirper=Authorization(Chirper),
)
@inlineCallbacks
def addChirp(chirper, value):
    # type: (Chirper, str) -> Deferred
    yield chirper.chirp(value)
    returnValue(Redirect(b"/"))
github twisted / klein / loginspike.py View on Github external
    binding=Authorization(ISimpleAccountBinding),
    sessionID=Field.text(),
    url=RequestURL(),
)
@inlineCallbacks
def logOtherOut(sessionID, binding, url):
    # type: (str, ISimpleAccountBinding, DecodedURL) -> Deferred
    from attr import assoc
    # TODO: public API for getting to this?
    session = yield binding._session._sessionStore.loadSession(
        sessionID, url.scheme == u'https', SessionMechanism.Header
    )
    other_binding = assoc(binding, _session=session)
    yield other_binding.unbindThisSession()
    returnValue(Redirect(b"/sessions"))