Пример #1
0
    def get(self, application_key):
        """ Obtains the data for an application

            Method: GET
            Path: /applications/{application_key}

            URI Parameters:
            application_key string              the key that identifies the application


            Request Parameters:
            pretty          [true|false]        whether to output in human readable format or not

            Parameters:
            :param application_key: the key that identifies the application

            Returns:
            :return: the data for the application
        """
        try:
            application = Application.get_by_id(application_key)
            json_result = {'applicationKey': application_key,
                           'name': application.name,
                           'description': application.description,
                           'clientSecret': application.client_secret,
                           'serverResponseKey': application.server_response_key}
            self.write_message(200, 'application', json_result)
        except AttributeError:
            self.write_error(400, 'Invalid application key')
Пример #2
0
    def post(self, application_key):
        """ Regenerates a server response key

            Method: POST
            Path: /applications/{application_key}/server/key

            URI Parameters:
            application_key string              the key that identifies the application

            Request Parameters:
            pretty          [true|false]        whether to output in human readable format or not

            Parameters:
            :param application_key: the key that identifies the application

            Returns
            :return: the new client secret key
        """
        try:
            application = Application.get_by_id(application_key)
            application.server_response_key = uuid4().hex
            application.put()
            self.write_message(200, 'serverResponseKey',
                               application.server_response_key)
        except AttributeError:
            self.write_message(400, 'Invalid application key')
Пример #3
0
    def get(self, application_key):
        """ Obtains the data for an application

            Method: GET
            Path: /applications/{application_key}

            URI Parameters:
            application_key string              the key that identifies the application


            Request Parameters:
            pretty          [true|false]        whether to output in human readable format or not

            Parameters:
            :param application_key: the key that identifies the application

            Returns:
            :return: the data for the application
        """
        try:
            application = Application.get_by_id(application_key)
            json_result = {
                'applicationKey': application_key,
                'name': application.name,
                'description': application.description,
                'clientSecret': application.client_secret,
                'serverResponseKey': application.server_response_key
            }
            self.write_message(200, 'application', json_result)
        except AttributeError:
            self.write_error(400, 'Invalid application key')
Пример #4
0
    def post(self, application_key):
        """ Regenerates a server response key

            Method: POST
            Path: /applications/{application_key}/server/key

            URI Parameters:
            application_key string              the key that identifies the application

            Request Parameters:
            pretty          [true|false]        whether to output in human readable format or not

            Parameters:
            :param application_key: the key that identifies the application

            Returns
            :return: the new client secret key
        """
        try:
            application = Application.get_by_id(application_key)
            application.server_response_key = uuid4().hex
            application.put()
            self.write_message(200, 'serverResponseKey', application.server_response_key)
        except AttributeError:
            self.write_message(400, 'Invalid application key')
Пример #5
0
    def get(self):
        """ Authenticates the client and sends it an access token

            Method: GET
            Path: /auth

            Request Parameters:
            applicationKey  string              key that identifies the client as an application
            clientSecret    string              secret key to prove the client's identity
            pretty          [true|false]        whether to output in human readable format or not

            Returns:
            :return: an access token if the application key and client secret are valid; otherwise
                     it sends the client an error
        """
        application_key = self.request.get("applicationKey")
        client_secret = self.request.get("clientSecret")
        if application_key is "":
            self.write_error(400, "No application key was provided")
            return
        if client_secret is "":
            self.write_error(400, "No client secret was provided")
            return
        application = Application.get_by_id(application_key)
        if application is None:
            self.write_error(400, "Invalid credentials")
            return
        if application.client_secret != client_secret:
            self.write_error(400, "Invalid credentials")
            return
        access_token = create_access_token(application_key)
        response_key = application.server_response_key
        self.write_signed_message(200, "accessToken", access_token, response_key)
Пример #6
0
    def __get_application(self):
        """ Gets the application that made the current request

            Returns:
            :return: the application if the access token is valid; None otherwise
        """
        if self.request.method in ['GET', 'DELETE']:
            access_token = self.request.get('accessToken')
        else:
            try:
                access_token = loads(self.request.body).get('accessToken')
            except ValueError:
                access_token = None
        if access_token is None:
            return None
        application_key = get_application_key(access_token)
        if not application_key:
            return None
        return Application.get_by_id(application_key)
Пример #7
0
    def __get_application(self):
        """ Gets the application that made the current request

            Returns:
            :return: the application if the access token is valid; None otherwise
        """
        if self.request.method in ['GET', 'DELETE']:
            access_token = self.request.get('accessToken')
        else:
            try:
                access_token = loads(self.request.body).get('accessToken')
            except ValueError:
                access_token = None
        if access_token is None:
            return None
        application_key = get_application_key(access_token)
        if not application_key:
            return None
        return Application.get_by_id(application_key)
Пример #8
0
    def put(self, application_key):
        """ Updates an application

            Method: PUT
            Path: /applications/{application_key}

            URI Parameters:
            application_key string              the key that identifies the application

            Request Parameters:
            application     JSON object         the new data for the application
            pretty          [true|false]        whether to output in human readable format or not

            Parameters:
            :param application_key: the key that identifies the application

            Returns:
            :return: the application key
        """
        application_data = self.get_from_body('application')
        application = Application.get_by_id(application_key)
        try:
            if application is not None:
                # Update application
                if application_data.get('name') is not None:
                    application.name = application_data['name']
                if application_data.get('description') is not None:
                    application.description = application_data['description']
                application.put()
                self.write_message(200, 'applicationKey', application_key)
            else:
                self.write_error(400, 'Invalid application key')
        except TransactionFailedError:
            self.write_error(400, 'Unable to store application')
        except BadValueError:
            # Thrown when model validations fail
            self.write_error(400, 'Invalid data')
Пример #9
0
    def put(self, application_key):
        """ Updates an application

            Method: PUT
            Path: /applications/{application_key}

            URI Parameters:
            application_key string              the key that identifies the application

            Request Parameters:
            application     JSON object         the new data for the application
            pretty          [true|false]        whether to output in human readable format or not

            Parameters:
            :param application_key: the key that identifies the application

            Returns:
            :return: the application key
        """
        application_data = self.get_from_body('application')
        application = Application.get_by_id(application_key)
        try:
            if application is not None:
                # Update application
                if application_data.get('name') is not None:
                    application.name = application_data['name']
                if application_data.get('description') is not None:
                    application.description = application_data['description']
                application.put()
                self.write_message(200, 'applicationKey', application_key)
            else:
                self.write_error(400, 'Invalid application key')
        except TransactionFailedError:
            self.write_error(400, 'Unable to store application')
        except BadValueError:
            # Thrown when model validations fail
            self.write_error(400, 'Invalid data')