Ejemplo n.º 1
0
 def addToMessage(self, message):
     message.update({
         fc('resource_link'): {
             'id': self.id,
             'title': self.label
         },
         fc('custom'): self.params
     })
     return message
Ejemplo n.º 2
0
 def addToMessage(self, message):
     message.update({fc('context'): self.context})
     return message
Ejemplo n.º 3
0
 def addToMessage(self, msg):
     updated = self.user.addToMessage(msg)
     updated.update({
         fc('roles'): [self.role]
     })
     return updated
Ejemplo n.º 4
0
 def addToMessage(self, msg):
     updated = copy(msg)
     updated[fc('tool_platform')] = {'name': self.name, 'guid': self.guid}
     return updated
Ejemplo n.º 5
0
    def message(self,
                messageType,
                course,
                member,
                message,
                return_url,
                request_url=None,
                resource_link=None,
                nonce=None):
        key = keys[randrange(0, len(keys))]
        privatekey = key[1].exportKey()
        now = int(time())
        root_url = request_url.rstrip(
            '/') if request_url else self.platform.url
        if nonce:
            message['nonce'] = nonce
        message.update({
            'iat': now,
            'exp': now + 60 * 10,
            'nonce': nonce,
            'iss': root_url,
            'aud': self.client_id,
            fc('deployment_id'): self.deployment_id,
            fc('message_type'): messageType,
            fc('version'): '1.3.0',
            fc('launch_presentation'): {
                "document_target": "iframe",
                "return_url": root_url + return_url
            }
        })
        ags_claim = {
            'scope': [
                scope('lineitem', s='ags'),
                scope('score', s='ags'),
                scope('result.readonly', s='ags')
            ],
            'lineitems':
            '{0}/{1}/lineitems'.format(root_url, course.id)
        }
        memberships_claim = {
            'context_memberships_url':
            '{0}/{1}/memberships'.format(root_url, course.id)
        }
        message = member.addToMessage(message)
        message = course.addToMessage(message)

        if resource_link:
            message = resource_link.addToMessage(message)
            if resource_link.lineitem:
                ags_claim[
                    'lineitem'] = '{0}/{1}/lineitems/{2}/lineitem'.format(
                        root_url, course.id, resource_link.lineitem.id)

        if fc('custom') in message:
            custom = message[fc('custom')]
            resolvers = [course, member]
            if resource_link:
                resolvers.append(resource_link)

            def resolve(item):
                value = item[1]
                for resolver in resolvers:
                    if len(value) == 0 or value[0] != '$':
                        break
                    value = resolver.resolve_param(value, member=member)
                return (item[0], value)

            message[fc('custom')] = dict(map(resolve, custom.items()))

        message[fc('endpoint', s='ags')] = ags_claim
        message[fc('namesroleservice', s='nrps')] = memberships_claim

        lti11_key = 'e2573-371879'
        lti11_key_sign = hmac_sha256_signature(
            'lti11-secret', '&'.join(
                (lti11_key, self.deployment_id, root_url, self.client_id,
                 str(message['exp']), nonce)))

        message[fc('lti1p1')] = {
            'oauth_consumer_key': lti11_key,
            'oauth_consumer_key_sign': lti11_key_sign
        }

        message = self.platform.addToMessage(message)
        return jwt.encode(message,
                          privatekey,
                          algorithm='RS256',
                          headers={'kid': key[0]})