Пример #1
0
    def _get_params() -> t.Generator:
        '''
        Formatted parameters to send to logger.
        '''

        yield dump_json({k: str(v) for k, v in token_params.items()})
        yield token[-5:]
        yield dump_json({'scope': scope.split()})

        _dict = {**params, 'client_assertion': params['client_assertion'][-5:]}

        yield dump_json({k: str(v) for k, v in _dict.items()})
Пример #2
0
    def post(self) -> None:
        '''
        Validates required login arguments sent from platform and then uses the
        authorize_redirect() method to redirect users to the authorization url.
        '''

        validator = LTI13LaunchValidator()

        args = LTIHelper.convert_request_to_dict(self.request.arguments)

        self.log.debug('Initial login request args are %s' % dump_json(
            {**args, 'lti_message_hint': args['lti_message_hint'][-5:]}))

        if validator.validate_login_request(args):

            login_hint = args['login_hint']

            self.log.debug('login_hint is %s' % login_hint)

            lti_message_hint = args['lti_message_hint']

            self.log.debug('lti_message_hint is %s' % lti_message_hint[-5:])

            client_id = args['client_id']

            self.log.debug('client_id is %s' % client_id)

            redirect_uri = guess_callback_uri(
                'https', self.request.host, self.hub.server.base_url)

            self.log.info('redirect_uri: %s' % redirect_uri)

            state = self.get_state()

            self.set_state_cookie(state)

            # TODO: validate that received nonces haven't been received before
            # and that they are within the time-based tolerance window

            nonce_raw = hashlib.sha256(state.encode())

            nonce = nonce_raw.hexdigest()

            self.authorize_redirect(
                client_id=client_id,
                login_hint=login_hint,
                lti_message_hint=lti_message_hint,
                nonce=nonce,
                redirect_uri=redirect_uri,
                state=state,
            )
Пример #3
0
    async def _get_line_item_info_by_assignment_name(self) -> str:
        '''
        Returns JSON.
        '''

        await self._get_lineitems_from_url(self.course.lms_lineitems_endpoint)

        if not self.all_lineitems:

            raise GradesSenderMissingInfoError(
                f'No line-items were detected for this course: {self.course_id}'
            )

        logger.debug(f'LineItems retrieved: {self.all_lineitems}')

        lineitem_matched = None

        logger.info(dump_json(self.all_lineitems))

        for item in self.all_lineitems:

            item_label = item['label']

            if (
                self.assignment_name.lower() == item_label.lower()
                or self.assignment_name.lower()
                == self.helper.format_string(item_label)
            ):
                lineitem_matched = item['id']  # the id is the full url
                logger.debug(
                    f'There is a lineitem matched with the assignment {self.assignment_name}. {item}'
                )
                break

        if lineitem_matched is None:
            raise GradesSenderMissingInfoError(
                f'No lineitem matched with the assignment name: {self.assignment_name}'
            )

        logger.info(f'Lineitem is {lineitem_matched}')

        logger.info(f'Item is {item}')

        return item
Пример #4
0
    def __init__(self, resp: t.Union[JsonType, Response]):

        content: str

        if isinstance(resp, Response):

            logger.error(
                'Response received from Moodle cannot be interpreted as JSON.')

            content = etree.tostring(html.fromstring(
                resp.content.decode('utf-8')),
                                     encoding='unicode',
                                     pretty_print=True)

        else:

            content = dump_json(resp)

        super().__init__(
            'Exception while calling Moodle API:'.center(39, '\n') + content)
Пример #5
0
 def __str__(self) -> str:
     return dump_json(self.resp)