Example #1
0
 def _validate_authorization_code(self):
     """
     Validate an authorization_code request.
     """
     if not self.code_key:
         raise InvalidRequest('No code_key provided')
     self.code = CodeDAO.get(key=self.code_key)
     if not self.code:
         raise InvalidRequest('No such code: %s' % self.code_key)
     if self.code.expire < time.time():
         raise InvalidGrant("Provided code is expired")
     if self.redirect_uri is None:
         raise InvalidRequest('No redirect_uri')
     if normalize(self.redirect_uri) != normalize(self.code.redirect_uri):
         raise InvalidRequest("redirect_uri doesn't match")
Example #2
0
 def validate(self, response_type, client_id, redirect_uri):
     """
     Validate the request params.
     """
     if not redirect_uri:
         raise exceptions.MissingRedirectURI("No redirect_uri provided.")
     if not response_type:
         raise exceptions.InvalidRequest("response_type is a required parameter.")
     if response_type not in ["code"]:
         raise exceptions.InvalidRequest("No such response type %s" % response_type)
     if not client_id:
         raise exceptions.InvalidRequest("client_id is a required parameter.")
     client = ClientDAO.get_client_by_key(client_id)
     if not client:
         raise exceptions.InvalidClient("client_id %s doesn't exist" % client_id)
     if not client.redirect_uri:
         raise exceptions.MissingRedirectURI("No redirect_uri registered.")
     if normalize(redirect_uri) != normalize(client.redirect_uri):
         raise exceptions.InvalidRequest("Registered redirect_uri doesn't match provided redirect_uri.")
     if not absolute_http_url_re.match(redirect_uri):
         raise exceptions.InvalidRequest("Absolute URI required for redirect_uri")
     return client