Esempio n. 1
0
    def exec_main_proc(self):
        create_params = {
            'clientName':
            self.params['name'],
            'description':
            self.params.get('description'),
            'applicationType':
            self.params['application_type'],
            'clientType':
            self.__get_client_type_from_application_type(
                self.params['application_type']),
            'developer':
            self.event['requestContext']['authorizer']['claims']
            ['cognito:username'],
            'redirectUris':
            self.params['redirect_urls'],
            'grantTypes': ['AUTHORIZATION_CODE', 'REFRESH_TOKEN'],
            'responseTypes': ['CODE']
        }
        try:
            response = requests.post(
                settings.AUTHLETE_CLIENT_ENDPOINT + '/create',
                json.dumps(create_params),
                headers={'Content-Type': 'application/json'},
                auth=(os.environ['AUTHLETE_API_KEY'],
                      os.environ['AUTHLETE_API_SECRET']))
        except requests.exceptions.RequestException as err:
            raise Exception(
                'Something went wrong when call Authlete API: {0}'.format(err))

        AuthleteUtil.verify_valid_response(response)

        return {'statusCode': 200, 'body': response.text}
    def exec_main_proc(self):
        request_params = {
                'start': self.params['start'],
                'end': self.params['end'],
                'subject': self.event['requestContext']['authorizer']['claims']['cognito:username']
        }
        try:
            response = requests.get(
                settings.AUTHLETE_CLIENT_ENDPOINT + '/authorization/get/list',
                params=request_params,
                auth=(os.environ['AUTHLETE_API_KEY'], os.environ['AUTHLETE_API_SECRET'])
            )

        except requests.exceptions.RequestException as err:
            raise Exception('Something went wrong when call Authlete API: {0}'.format(err))

        AuthleteUtil.verify_valid_response(response)

        result = []
        for client in json.loads(response.text).get('clients', []):
            result.append({
                'clientId': client['clientId'],
                'clientName': client['clientName'],
                'clientType': client['clientType'],
                'createdAt': client['createdAt'],
                'description': client.get('description')
            })

        return {
            'statusCode': 200,
            'body': json.dumps(result)
        }
Esempio n. 3
0
    def test_is_accessible_client_404(self):
        client_id = 123456789
        user_id = 'user01'

        responses.add(responses.GET,
                      settings.AUTHLETE_CLIENT_ENDPOINT + '/get/' +
                      str(client_id),
                      json={},
                      status=404)

        with self.assertRaises(RecordNotFoundError):
            AuthleteUtil.is_accessible_client(client_id, user_id)
    def exec_main_proc(self):
        try:
            response = requests.get(settings.AUTHLETE_CLIENT_ENDPOINT +
                                    '/get/' + str(self.params['client_id']),
                                    auth=(os.environ['AUTHLETE_API_KEY'],
                                          os.environ['AUTHLETE_API_SECRET']))
        except requests.exceptions.RequestException as err:
            raise Exception(
                'Something went wrong when call Authlete API: {0}'.format(err))

        AuthleteUtil.verify_valid_response(
            response, request_client_id=self.params['client_id'])

        return {'statusCode': 200, 'body': response.text}
    def validate_params(self):
        ParameterUtil.cast_parameter_to_int(self.params, self.get_schema())
        validate(self.params, self.get_schema())

        user_id = self.event['requestContext']['authorizer']['claims']['cognito:username']

        if not AuthleteUtil.is_accessible_client(self.params['client_id'], user_id):
            raise NoPermissionError('No permission on this resource')
    def exec_main_proc(self):
        subject = self.event['requestContext']['authorizer']['claims'][
            'cognito:username']
        url = settings.AUTHLETE_CLIENT_ENDPOINT + '/authorization/delete/' + str(
            self.params['client_id']) + '/' + subject
        try:
            response = requests.delete(
                url,
                auth=(os.environ['AUTHLETE_API_KEY'],
                      os.environ['AUTHLETE_API_SECRET']))
        except requests.exceptions.RequestException as err:
            raise Exception(
                'Something went wrong when call Authlete API: {0}'.format(err))

        AuthleteUtil.verify_valid_response(
            response, request_client_id=self.params['client_id'])

        return {'statusCode': 200, 'body': '{"result": "OK"}'}
Esempio n. 7
0
    def test_is_accessible_client_ok_false(self):
        client_id = 123456789
        user_id = 'user01'

        responses.add(responses.GET,
                      settings.AUTHLETE_CLIENT_ENDPOINT + '/get/' +
                      str(client_id),
                      json={'developer': user_id},
                      status=200)

        result = AuthleteUtil.is_accessible_client(client_id, 'user02')
        self.assertEqual(result, False)
Esempio n. 8
0
    def exec_main_proc(self):
        index_params = {
            'developer':
            self.event['requestContext']['authorizer']['claims']
            ['cognito:username']
        }

        try:
            response = requests.get(settings.AUTHLETE_CLIENT_ENDPOINT +
                                    '/get/list',
                                    params=index_params,
                                    auth=(os.environ['AUTHLETE_API_KEY'],
                                          os.environ['AUTHLETE_API_SECRET']))

        except requests.exceptions.RequestException as err:
            raise Exception(
                'Something went wrong when call Authlete API: {0}'.format(err))

        AuthleteUtil.verify_valid_response(response)

        return {'statusCode': 200, 'body': response.text}
Esempio n. 9
0
    def test_is_accessible_client_with_exception(self):
        client_id = 123456789
        user_id = 'user01'

        with self.assertRaises(Exception):
            AuthleteUtil.is_accessible_client(client_id, user_id)