(self)
Validate the request.
Validate the request.
Validate the request .
def _validate(self):
        """Validate the request."""
        # Check response type
        if self.grant_type is None:
            raise InvalidRequest('No grant_type provided.')
        if self.grant_type not in [
                "authorization_code",
                "refresh_token",
                "password",
                "client_credentials"]:
            raise UnsupportedGrantType('No grant type: %s' % self.grant_type)
        if self.client_id is None:
            raise InvalidRequest('No client_id')
        try:
            self.client = Client.objects.get(key=self.client_id)
        except Client.DoesNotExist:
            raise InvalidClient("client_id %s doesn't exist" % self.client_id)
        # Scope
        if self.scope is not None:
            access_ranges = AccessRange.objects.filter(key__in=self.scope)
            access_ranges = set(access_ranges.values_list('key', flat=True))
            difference = access_ranges.symmetric_difference(self.scope)
            if len(difference) != 0:
                raise InvalidScope("Following access ranges doesn't exist: "
                    "%s" % ', '.join(difference))
        if self.grant_type == "authorization_code":
            self._validate_authorization_code()
        elif self.grant_type == "refresh_token":
            self._validate_refresh_token()
        elif self.grant_type == "password":
            self._validate_password()
        elif self.grant_type == "client_credentials":
            self._validate_client_credentials()
        else:
            raise UnsupportedGrantType('Unable to validate grant type.')
def _validate ( self ) : # Check response type if self . grant_type is None : raise InvalidRequest ( 'No grant_type provided.' ) if self . grant_type not in [ "authorization_code" , "refresh_token" , "password" , "client_credentials" ] : raise UnsupportedGrantType ( 'No grant type: %s' % self . grant_type ) if self . client_id is None : raise InvalidRequest ( 'No client_id' ) try : self . client = Client . objects . get ( key = self . client_id ) except Client . DoesNotExist : raise InvalidClient ( "client_id %s doesn't exist" % self . client_id ) # Scope if self . scope is not None : access_ranges = AccessRange . objects . filter ( key__in = self . scope ) access_ranges = set ( access_ranges . values_list ( 'key' , flat = True ) ) difference = access_ranges . symmetric_difference ( self . scope ) if len ( difference ) != 0 : raise InvalidScope ( "Following access ranges doesn't exist: " "%s" % ', ' . join ( difference ) ) if self . grant_type == "authorization_code" : self . _validate_authorization_code ( ) elif self . grant_type == "refresh_token" : self . _validate_refresh_token ( ) elif self . grant_type == "password" : self . _validate_password ( ) elif self . grant_type == "client_credentials" : self . _validate_client_credentials ( ) else : raise UnsupportedGrantType ( 'Unable to validate grant type.' )