def test_authn_event():
    an = AuthnEvent(
        uid="uid",
        salt="_salt_",
        valid_until=time_sans_frac() + 1,
        authn_info="authn_class_ref",
    )

    assert an.valid()

    n = time_sans_frac() + 3
    assert an.valid(n) is False

    n = an.expires_in()
    assert n == 1  # could possibly be 0
Beispiel #2
0
def setup_session(
        endpoint_context, areq, uid, client_id="", acr="", salt="salt", authn_event=None
):
    """
    Setting up a user session

    :param endpoint_context:
    :param areq:
    :param uid:
    :param acr:
    :param client_id:
    :param salt:
    :param authn_event: A already made AuthnEvent
    :return:
    """
    if authn_event is None and acr:
        authn_event = AuthnEvent(
            uid=uid, salt=salt, authn_info=acr, authn_time=time.time()
        )

    if not client_id:
        client_id = areq["client_id"]

    sid = endpoint_context.sdb.create_authz_session(
        authn_event, areq, client_id=client_id, uid=uid
    )

    client_salt = endpoint_context.cdb.get(client_id, {}).get("client_salt", salt)
    endpoint_context.sdb.do_sub(sid, uid, client_salt)
    return sid
Beispiel #3
0
    def authn_verify(self, url_endpoint, **kwargs):
        """
        Authentication verification

        :param authn_method: Which authn method that was used
        :param kwargs: response arguments
        :return: HTTP redirect
        """
        authn_method = self.endpoint_context.endpoint_to_authn_method[
            url_endpoint]

        username = authn_method.verify(**kwargs)
        if not username:
            cherrypy.HTTPError(403, message='Authentication failed')

        auth_args = authn_method.unpack_token(kwargs['token'])
        request = AuthorizationRequest().from_urlencoded(auth_args['query'])

        authn_event = AuthnEvent(uid=username, salt='salt',
                                 authn_info=auth_args['authn_class_ref'],
                                 authn_time=auth_args['iat'])

        endpoint = self.endpoint_context.endpoint['authorization']
        args = endpoint.post_authentication(request,
                                            user=username,
                                            sid=request['state'],
                                            authn_event=authn_event)

        return self.do_response(endpoint, request, **args)
def setup_session(endpoint_context, areq):
    authn_event = AuthnEvent(uid="uid", salt='salt',
                             authn_info=INTERNETPROTOCOLPASSWORD,
                             time_stamp=time.time())
    sid = endpoint_context.sdb.create_authz_session(authn_event, areq,
                                                    client_id='client_id')
    endpoint_context.sdb.do_sub(sid, '')
    return sid
Beispiel #5
0
def authn_event_deser(val, sformat="urlencoded"):
    if sformat in ["dict", "json"]:
        if not isinstance(val, str):
            val = json.dumps(val)
            sformat = "json"
    return AuthnEvent().deserialize(val, sformat)