src/scitokens/scitokens.py
def deserialize(serialized_token, audience=None, require_key=False, insecure=False, public_key=None):
        """
        Given a serialized SciToken, load it into a SciTokens object.

        Verifies the claims pass the current set of validation scripts.
        
        :param str serialized_token: The serialized token.
        :param str audience: The audience URI that this principle is claiming.  Default: None
        :param bool require_key: When True, require the key
        :param bool insecure: When True, allow insecure methods to verify the issuer,
                              including allowing "localhost" issuer (useful in testing).  Default=False
        :param str public_key: A PEM formatted public key string to be used to validate the token
        """

        if require_key is not False:
            raise NotImplementedError()

        if isinstance(serialized_token, bytes):
            serialized_token = serialized_token.decode('utf8')
        info = serialized_token.split(".")

        if len(info) != 3 and len(info) != 4: # header, format, signature[, key]
            raise InvalidTokenFormat("Serialized token is not a readable format.")

        if (len(info) != 4) and require_key:
            raise MissingKeyException("No key present in serialized token")

        serialized_jwt = info[0] + "." + info[1] + "." + info[2]

        unverified_headers = jwt.get_unverified_header(serialized_jwt)
        unverified_payload = jwt.decode(serialized_jwt, verify=False, algorithms=['RS256', 'ES256'])
        
        # Get the public key from the issuer
        keycache = KeyCache.KeyCache().getinstance()
        if public_key == None:
            issuer_public_key = keycache.getkeyinfo(unverified_payload['iss'],
                                key_id=unverified_headers['kid'] if 'kid' in unverified_headers else None,
                                insecure=insecure)
        else:
            issuer_public_key = load_pem_public_key(public_key, backend=backends.default_backend())
        
        if audience:
            claims = jwt.decode(serialized_token, issuer_public_key, audience = audience)
        else:
            claims = jwt.decode(serialized_token, issuer_public_key)
        # Do we have the private key?
        if len(info) == 4:
            to_return = SciToken(key = key)
        else:
            to_return = SciToken()
            
        to_return._verified_claims = claims
        to_return._serialized_token = serialized_token
        return to_return

        Given a serialized SciToken, load it into a SciTokens object.

        Verifies the claims pass the current set of validation scripts.
        
        :param str serialized_token: The serialized token.
        :param str audience: The audience URI that this principle is claiming.  Default: None
        :param bool require_key: When True, require the key
        :param bool insecure: When True, allow insecure methods to verify the issuer,
                              including allowing "localhost" issuer (useful in testing).  Default=False
        :param str public_key: A PEM formatted public key string to be used to validate the token
        
Given a serialized SciToken, load it into a SciTokens object.
Verifies the claims pass the current set of validation scripts.
Given a serialized SciToken load it into a SciTokens object . Verifies the claims pass the current set of validation scripts .
def deserialize(serialized_token, audience=None, require_key=False, insecure=False, public_key=None):
        if require_key is not False:
            raise NotImplementedError()
        if isinstance(serialized_token, bytes):
            serialized_token = serialized_token.decode('utf8')
        info = serialized_token.split(".")
        if len(info) != 3 and len(info) != 4: 
            raise InvalidTokenFormat("Serialized token is not a readable format.")
        if (len(info) != 4) and require_key:
            raise MissingKeyException("No key present in serialized token")
        serialized_jwt = info[0] + "." + info[1] + "." + info[2]
        unverified_headers = jwt.get_unverified_header(serialized_jwt)
        unverified_payload = jwt.decode(serialized_jwt, verify=False, algorithms=['RS256', 'ES256'])
        keycache = KeyCache.KeyCache().getinstance()
        if public_key == None:
            issuer_public_key = keycache.getkeyinfo(unverified_payload['iss'],
                                key_id=unverified_headers['kid'] if 'kid' in unverified_headers else None,
                                insecure=insecure)
        else:
            issuer_public_key = load_pem_public_key(public_key, backend=backends.default_backend())
        if audience:
            claims = jwt.decode(serialized_token, issuer_public_key, audience = audience)
        else:
            claims = jwt.decode(serialized_token, issuer_public_key)
        if len(info) == 4:
            to_return = SciToken(key = key)
        else:
            to_return = SciToken()
        to_return._verified_claims = claims
        to_return._serialized_token = serialized_token
        return to_return
def deserialize ( serialized_token , audience = None , require_key = False , insecure = False , public_key = None ) : if require_key is not False : raise NotImplementedError ( ) if isinstance ( serialized_token , bytes ) : serialized_token = serialized_token . decode ( 'utf8' ) info = serialized_token . split ( "." ) if len ( info ) != 3 and len ( info ) != 4 : raise InvalidTokenFormat ( "Serialized token is not a readable format." ) if ( len ( info ) != 4 ) and require_key : raise MissingKeyException ( "No key present in serialized token" ) serialized_jwt = info [ 0 ] + "." + info [ 1 ] + "." + info [ 2 ] unverified_headers = jwt . get_unverified_header ( serialized_jwt ) unverified_payload = jwt . decode ( serialized_jwt , verify = False , algorithms = [ 'RS256' , 'ES256' ] ) keycache = KeyCache . KeyCache ( ) . getinstance ( ) if public_key == None : issuer_public_key = keycache . getkeyinfo ( unverified_payload [ 'iss' ] , key_id = unverified_headers [ 'kid' ] if 'kid' in unverified_headers else None , insecure = insecure ) else : issuer_public_key = load_pem_public_key ( public_key , backend = backends . default_backend ( ) ) if audience : claims = jwt . decode ( serialized_token , issuer_public_key , audience = audience ) else : claims = jwt . decode ( serialized_token , issuer_public_key ) if len ( info ) == 4 : to_return = SciToken ( key = key ) else : to_return = SciToken ( ) to_return . _verified_claims = claims to_return . _serialized_token = serialized_token return to_return
Given a serialized SciToken, load it into a SciTokens object.
Given a serialized SciToken load it into a SciTokens object .
"""
        Given a serialized SciToken, load it into a SciTokens object.

        Verifies the claims pass the current set of validation scripts.
        
        :param str serialized_token: The serialized token.
        :param str audience: The audience URI that this principle is claiming.  Default: None
        :param bool require_key: When True, require the key
        :param bool insecure: When True, allow insecure methods to verify the issuer,
                              including allowing "localhost" issuer (useful in testing).  Default=False
        :param str public_key: A PEM formatted public key string to be used to validate the token
        """ # header, format, signature[, key] # Get the public key from the issuer # Do we have the private key?
serialized_token
The serialized token.
The serialized token .
audience
The audience URI that this principle is claiming.  Default: None
The audience URI that this principle is claiming . Default : None
require_key
When True, require the key
When True require the key
insecure
When True, allow insecure methods to verify the issuer,
including allowing "localhost" issuer (useful in testing).  Default=False
When True allow insecure methods to verify the issuer including allowing " localhost " issuer ( useful in testing ) . Default = False
public_key
A PEM formatted public key string to be used to validate the token
A PEM formatted public key string to be used to validate the token