async def test_join_jwe(guillotina_hydraidp_requester):
    requester = guillotina_hydraidp_requester

    from guillotina_hydraidp import utils
    from Crypto.PublicKey import RSA
    from guillotina import jose

    key = RSA.generate(2048)
    pub_jwk = key.publickey().exportKey('PEM')
    priv_jwk = key.exportKey('PEM')
    utils.REGISTRATION_KEY = {'k': priv_jwk}

    payload = {
        'username': '******',
        'password': '******'
    }

    jwe = jose.encrypt(payload, {'k': pub_jwk})
    token = jose.serialize_compact(jwe).decode('utf-8')

    resp, status = await requester('POST', '/@hydra-join', data=json.dumps(
        {'encrypted': token}))
    assert status == 200

    resp, status = await requester('GET', '/@users')
    assert len(resp) == 1
Exemple #2
0
 def generate_websocket_token(self, real_token):
     claims = {
         'iat': int(time.time()),
         'exp': int(time.time() + self._websockets_ttl),
         'token': real_token
     }
     jwe = jose.encrypt(claims, app_settings['rsa']['priv'])
     token = jose.serialize_compact(jwe)
     return token.decode('utf-8')
Exemple #3
0
    def generate_websocket_token(self, real_token):
        exp = datetime.utcnow() + timedelta(seconds=self._websockets_ttl)

        claims = {
            'iat': int(datetime.utcnow().timestamp()),
            'exp': int(exp.timestamp()),
            'token': real_token
        }
        jwe = jose.encrypt(claims, app_settings['rsa']['priv'])
        token = jose.serialize_compact(jwe)
        return token.decode('utf-8')
Exemple #4
0
async def test_encrypt_descrypt():
    claims = {
        'iat': int(time.time()),
        'exp': int(time.time() + 30),
        'token': 'foobar'
    }
    jwe = jose.encrypt(claims, priv_jwk)
    encrypted_token = jose.serialize_compact(jwe)
    jwe = jose.deserialize_compact(encrypted_token)
    jwt = jose.decrypt(jwe, priv_jwk)
    assert jwt.claims == claims