Esempio n. 1
0
 def validate_at_hash(self):
     """If the ID Token is issued from the Authorization Endpoint with an
     access_token value, which is the case for the response_type value
     id_token token, this is REQUIRED; it MAY NOT be used when no Access
     Token is issued, which is the case for the response_type value
     id_token.
     """
     access_token = self.params.get('access_token')
     if access_token and 'at_hash' not in self:
         raise MissingClaimError('at_hash')
     super(ImplicitIDToken, self).validate_at_hash()
Esempio n. 2
0
    def validate_auth_time(self):
        """Time when the End-User authentication occurred. Its value is a JSON
        number representing the number of seconds from 1970-01-01T0:0:0Z as
        measured in UTC until the date/time. When a max_age request is made or
        when auth_time is requested as an Essential Claim, then this Claim is
        REQUIRED; otherwise, its inclusion is OPTIONAL.
        """
        auth_time = self.get('auth_time')
        if self.params.get('max_age') and not auth_time:
            raise MissingClaimError('auth_time')

        if auth_time and not isinstance(auth_time, int):
            raise InvalidClaimError('auth_time')
Esempio n. 3
0
 def validate_nonce(self):
     """String value used to associate a Client session with an ID Token,
     and to mitigate replay attacks. The value is passed through unmodified
     from the Authentication Request to the ID Token. If present in the ID
     Token, Clients MUST verify that the nonce Claim Value is equal to the
     value of the nonce parameter sent in the Authentication Request. If
     present in the Authentication Request, Authorization Servers MUST
     include a nonce Claim in the ID Token with the Claim Value being the
     nonce value sent in the Authentication Request. Authorization Servers
     SHOULD perform no other processing on nonce values used. The nonce
     value is a case sensitive string.
     """
     nonce_value = self.params.get('nonce')
     if nonce_value:
         if 'nonce' not in self:
             raise MissingClaimError('nonce')
         if nonce_value != self['nonce']:
             raise InvalidClaimError('nonce')
Esempio n. 4
0
 def validate_c_hash(self):
     """Code hash value. Its value is the base64url encoding of the
     left-most half of the hash of the octets of the ASCII representation
     of the code value, where the hash algorithm used is the hash algorithm
     used in the alg Header Parameter of the ID Token's JOSE Header. For
     instance, if the alg is HS512, hash the code value with SHA-512, then
     take the left-most 256 bits and base64url encode them. The c_hash
     value is a case sensitive string.
     If the ID Token is issued from the Authorization Endpoint with a code,
     which is the case for the response_type values code id_token and code
     id_token token, this is REQUIRED; otherwise, its inclusion is OPTIONAL.
     """
     code = self.params.get('code')
     c_hash = self.get('c_hash')
     if code:
         if not c_hash:
             raise MissingClaimError('c_hash')
         if not _verify_hash(c_hash, code, self.header['alg']):
             raise InvalidClaimError('c_hash')
Esempio n. 5
0
    def validate_azp(self):
        """OPTIONAL. Authorized party - the party to which the ID Token was
        issued. If present, it MUST contain the OAuth 2.0 Client ID of this
        party. This Claim is only needed when the ID Token has a single
        audience value and that audience is different than the authorized
        party. It MAY be included even when the authorized party is the same
        as the sole audience. The azp value is a case sensitive string
        containing a StringOrURI value.
        """
        aud = self.get('aud')
        client_id = self.params.get('client_id')
        required = False
        if aud and client_id:
            if isinstance(aud, list) and len(aud) == 1:
                aud = aud[0]
            if aud != client_id:
                required = True

        azp = self.get('azp')
        if required and not azp:
            raise MissingClaimError('azp')

        if azp and client_id and azp != client_id:
            raise InvalidClaimError('azp')
Esempio n. 6
0
 def _validate_essential_claims(self):
     super(IDToken, self)._validate_essential_claims()
     for k in self.ESSENTIAL_CLAIMS:
         if k not in self:
             raise MissingClaimError(k)