예제 #1
0
def encoded_jwt(kid, rsa_private_key):
    """
    Return an example JWT containing the claims and encoded with the private
    key.
    Args:
        rsa_private_key (str): fixture
    Return:
        str: JWT containing claims encoded with private key
    """
    headers = {"kid": kid}
    return jwt.encode(
        utils.default_claims(), key=rsa_private_key, headers=headers, algorithm="RS256"
    ).decode("utf-8")
def encoded_admin_jwt(kid, rsa_private_key):
    """
    To use this fixture you need to also include admin_user as a fixture
    in your test (admin_user must be in the db).
    """
    headers = {"kid": kid}
    claims = utils.default_claims()
    claims["context"]["user"]["name"] = "*****@*****.**"
    claims["aud"].append("admin")
    claims["sub"] = "5678"
    claims["iss"] = config["BASE_URL"]
    claims["exp"] += 600
    return jwt.encode(claims, key=rsa_private_key, headers=headers, algorithm="RS256")
예제 #3
0
def encoded_jwt_expired(kid, rsa_private_key):
    """
    Return an example JWT that has already expired.
    Args:
        rsa_private_key (str): fixture
    Return:
        str: JWT containing claims encoded with private key
    """
    headers = {"kid": kid}
    claims_expired = utils.default_claims()
    # Move `exp` and `iat` into the past.
    claims_expired["exp"] -= 10000
    claims_expired["iat"] -= 10000
    return jwt.encode(
        claims_expired, key=rsa_private_key, headers=headers, algorithm="RS256"
    ).decode("utf-8")
예제 #4
0
def encoded_jwt(private_key):
    """
    Return an example JWT containing the claims and encoded with the private
    key.

    Args:
        claims (dict): fixture
        private_key (str): fixture

    Return:
        str: JWT containing claims encoded with private key
    """
    kid = test_settings.JWT_KEYPAIR_FILES.keys()[0]
    headers = {'kid': kid}
    return jwt.encode(
        utils.default_claims(),
        key=private_key,
        headers=headers,
        algorithm='RS256',
    )
예제 #5
0
def encoded_jwt_expired(claims, private_key):
    """
    Return an example JWT that has already expired.

    Args:
        claims (dict): fixture
        private_key (str): fixture

    Return:
        str: JWT containing claims encoded with private key
    """
    kid = test_settings.JWT_KEYPAIR_FILES.keys()[0]
    headers = {'kid': kid}
    claims_expired = utils.default_claims()
    # Move `exp` and `iat` into the past.
    claims_expired['exp'] -= 10000
    claims_expired['iat'] -= 10000
    return jwt.encode(
        claims_expired, key=private_key, headers=headers, algorithm='RS256'
    )