Ejemplo n.º 1
0
def test_private_key_jwt_reusage_other_endpoint():
    # Own dynamic keys
    client_keyjar = build_keyjar(KEYDEFS)
    # The servers keys
    client_keyjar[conf["issuer"]] = KEYJAR.issuer_keys[""]

    _jwks = client_keyjar.export_jwks()
    endpoint_context.keyjar.import_jwks(_jwks, client_id)

    _jwt = JWT(client_keyjar, iss=client_id, sign_alg="RS256")
    _jwt.with_jti = True
    _assertion = _jwt.pack(
        {"aud": [endpoint_context.endpoint["token"].full_path]})

    request = {
        "client_assertion": _assertion,
        "client_assertion_type": JWT_BEARER
    }

    # This should be OK
    PrivateKeyJWT(endpoint_context).verify(request, endpoint="token")

    # This should NOT be OK
    with pytest.raises(NotForMe):
        PrivateKeyJWT(endpoint_context).verify(request,
                                               endpoint="authorization")

    # This should NOT be OK
    with pytest.raises(MultipleUsage):
        PrivateKeyJWT(endpoint_context).verify(request, endpoint="token")
Ejemplo n.º 2
0
def add_support(endpoint, **kwargs):
    """

    :param endpoint:
    :param kwargs:
    :return:
    """
    for endp in kwargs.get('where', []):  # ["authorization", "pushed_authorization"]
        auth_endpoint = endpoint.get(endp)

        if auth_endpoint is None and endp == 'authorization':
            auth_endpoint = endpoint.get('federation_{}'.format(endp))

        if auth_endpoint:
            auto_reg = registration.Registration(auth_endpoint.endpoint_context, **kwargs)
            auth_endpoint.automatic_registration_endpoint = auto_reg

            if endp == 'authorization':
                if not auth_endpoint.client_authn_method:
                    auth_endpoint.client_authn_method = [
                        RequestParam(auth_endpoint.endpoint_context)]
            else:  # pushed_authorization
                if not auth_endpoint.client_authn_method:
                    auth_endpoint.client_authn_method = [
                        PrivateKeyJWT(auth_endpoint.endpoint_context)]

            _pi = auth_endpoint.endpoint_context.provider_info
            _supported = kwargs.get('client_registration_authn_methods_supported')
            if _supported:
                _pi['client_registration_authn_methods_supported'] = _supported
Ejemplo n.º 3
0
def test_private_key_jwt():
    # Own dynamic keys
    client_keyjar = build_keyjar(KEYDEFS)[1]
    # The servers keys
    client_keyjar[conf['issuer']] = KEYJAR.issuer_keys['']

    _jwks = client_keyjar.export_jwks()
    endpoint_context.keyjar.import_jwks(_jwks, client_id)

    _jwt = JWT(client_keyjar, iss=client_id, sign_alg='RS256')
    _assertion = _jwt.pack({'aud': [conf['issuer']]})

    request = {'client_assertion': _assertion,
               'client_assertion_type': JWT_BEARER}

    authn_info = PrivateKeyJWT(endpoint_context).verify(request)

    assert authn_info['client_id'] == client_id
    assert 'jwt' in authn_info
Ejemplo n.º 4
0
def test_private_key_jwt():
    # Own dynamic keys
    client_keyjar = build_keyjar(KEYDEFS)
    # The servers keys
    client_keyjar[conf["issuer"]] = KEYJAR.issuer_keys[""]

    _jwks = client_keyjar.export_jwks()
    endpoint_context.keyjar.import_jwks(_jwks, client_id)

    _jwt = JWT(client_keyjar, iss=client_id, sign_alg="RS256")
    _assertion = _jwt.pack({"aud": [conf["issuer"]]})

    request = {
        "client_assertion": _assertion,
        "client_assertion_type": JWT_BEARER
    }

    authn_info = PrivateKeyJWT(endpoint_context).verify(request)

    assert authn_info["client_id"] == client_id
    assert "jwt" in authn_info
Ejemplo n.º 5
0
 def create_method(self):
     self.method = PrivateKeyJWT(endpoint_context)