예제 #1
0
    def _configure(self, is_enabled, whitelist=None):
        """Enable or disable the end-point and configure the whitelist. """
        config = XDomainProxyConfiguration.current()
        config.enabled = is_enabled

        if whitelist:
            config.whitelist = "\n".join(whitelist)

        config.save()
        cache.clear()
예제 #2
0
파일: views.py 프로젝트: epixia/spark
def xdomain_proxy(request):  # pylint: disable=unused-argument
    """Serve the xdomain proxy page.

    Internet Explorer 9 does not send cookie information with CORS,
    which means we can't make cross-domain POST requests that
    require authentication (for example, from the course details
    page on the marketing site to the enrollment API
    to auto-enroll a user in an "honor" track).

    The XDomain library [https://github.com/jpillora/xdomain]
    provides an alternative to using CORS.

    The library works as follows:

    1) A static HTML file ("xdomain_proxy.html") is served from courses.edx.org.
       The file includes JavaScript and a domain whitelist.

    2) The course details page (on edx.org) creates an invisible iframe
       that loads the proxy HTML file.

    3) A JS shim library on the course details page intercepts
       AJAX requests and communicates with JavaScript on the iframed page.
       The iframed page then proxies the request to the LMS.
       Since the iframed page is served from courses.edx.org,
       this is a same-domain request, so all cookies for the domain
       are sent along with the request.

    You can enable this feature and configure the domain whitelist
    using Django admin.

    """
    config = XDomainProxyConfiguration.current()
    if not config.enabled:
        return HttpResponseNotFound()

    allowed_domains = []
    for domain in config.whitelist.split("\n"):  # pylint: disable=no-member
        if domain.strip():
            allowed_domains.append(domain.strip())

    if not allowed_domains:
        log.warning(
            u"No whitelist configured for cross-domain proxy. "
            u"You can configure the whitelist in Django Admin "
            u"using the XDomainProxyConfiguration model."
        )
        return HttpResponseNotFound()

    context = {
        'xdomain_masters': json.dumps({
            domain: '*'
            for domain in allowed_domains
        })
    }
    return render_to_response('cors_csrf/xdomain_proxy.html', context)