コード例 #1
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')
コード例 #2
0
 def validate_amr(self):
     """OPTIONAL. Authentication Methods References. JSON array of strings
     that are identifiers for authentication methods used in the
     authentication. For instance, values might indicate that both password
     and OTP authentication methods were used. The definition of particular
     values to be used in the amr Claim is beyond the scope of this
     specification. Parties using this claim will need to agree upon the
     meanings of the values used, which may be context-specific. The amr
     value is an array of case sensitive strings.
     """
     amr = self.get('amr')
     if amr and not isinstance(self['amr'], list):
         raise InvalidClaimError('amr')
コード例 #3
0
 def validate_at_hash(self):
     """OPTIONAL. Access Token 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 access_token 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 RS256, hash the
     access_token value with SHA-256, then take the left-most 128 bits and
     base64url encode them. The at_hash value is a case sensitive string.
     """
     access_token = self.params.get('access_token')
     at_hash = self.get('at_hash')
     if at_hash and access_token:
         if not _verify_hash(at_hash, access_token, self.header['alg']):
             raise InvalidClaimError('at_hash')
コード例 #4
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')
コード例 #5
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')
コード例 #6
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')