Example #1
0
def run_xblock_handler_noauth(*args, **kwargs):
    """
    Import and run `handle_xblock_callback_noauth` from LMS
    """
    # pylint: disable=import-error,import-outside-toplevel
    from lms.djangoapps.courseware.module_render import handle_xblock_callback_noauth
    return handle_xblock_callback_noauth(*args, **kwargs)
Example #2
0
def call_xblock_json_handler(request,
                             usage_id,
                             handler_name,
                             data,
                             auth=False):
    """
    WARN: Tested only for use in ESG. Consult before use outside of ESG.

    Create an internally-routed XBlock.json_handler request. The internal auth code/param unpacking requires a POST
    request with payload in the body. Ideally, we would be able to call functions on XBlocks without this sort of
    hacky request proxying but this is what we have to work with right now.

    params:
        request (HttpRequest): Originating web request, we're going to borrow auth headers/cookies from this
        usage_id (str): Usage ID of the XBlock for running the handler
        handler_name (str): the name of the XBlock handler method
        data (dict): Data to be encoded and sent as the body of the POST request
    returns:
        response (HttpResponse): get response data with json.loads(response.content)
    """
    # XBlock.json_handler operates through a POST request
    proxy_request = clone_request(request, "POST")
    proxy_request.META["REQUEST_METHOD"] = "POST"

    # The body is an encoded JSON blob
    proxy_request.body = json.dumps(data).encode()

    # Course ID can be retrieved from the usage_id
    usage_key = UsageKey.from_string(usage_id)
    course_id = str(usage_key.course_key)

    # Send the request and return the HTTP response from the XBlock
    return handle_xblock_callback_noauth(proxy_request, course_id, usage_id,
                                         handler_name)
Example #3
0
def access_token_endpoint(request, usage_id=None):
    """
    Gate endpoint to enable tools to retrieve access tokens
    """
    try:
        usage_key = UsageKey.from_string(usage_id)

        return handle_xblock_callback_noauth(request=request,
                                             course_id=str(
                                                 usage_key.course_key),
                                             usage_id=str(usage_key),
                                             handler='lti_1p3_access_token')
    except:  # pylint: disable=bare-except
        return HttpResponse(status=404)
Example #4
0
def public_keyset_endpoint(request, usage_id=None):
    """
    Gate endpoint to fetch public keysets from a problem

    This is basically a passthrough function that uses the
    OIDC response parameter `login_hint` to locate the block
    and run the proper handler.
    """
    try:
        usage_key = UsageKey.from_string(usage_id)

        return handle_xblock_callback_noauth(request=request,
                                             course_id=str(
                                                 usage_key.course_key),
                                             usage_id=str(usage_key),
                                             handler='public_keyset_endpoint')
    except:  # pylint: disable=bare-except
        return HttpResponse(status=404)