toolkit/components/extensions/test/mochitest/redirect_auto.sjs
author Shane Caraveo <scaraveo@mozilla.com>
Fri, 28 Sep 2018 13:18:00 +0000
changeset 490159 3947b51293f6f3ddd8173b263cee69f7e4850a45
parent 365083 c7054d08b878904bc413750fc7a70d6ea649c9e8
child 523197 5d798451164267c5f4a4b69684361bc028d3d07a
permissions -rw-r--r--
Bug 1494328 fix launchWebAuthFlow to use default redirect_uri r=aswan a=pascalc Some oauth services require the redirect uri be configured on their service, and the reject the redirect_uri param if we send it. Chrome works fine in this scenario, but we have been requiring the redirect_uri be provided. This addresses that requirement by using our own default redirect url, which would be the url used to configure the oauth service. Differential Revision: https://phabricator.services.mozilla.com/D6945

/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/
 */
Components.utils.importGlobalProperties(["URLSearchParams", "URL"]);

function handleRequest(request, response) {
  let params = new URLSearchParams(request.queryString);
  if (params.has("no_redirect")) {
    response.setStatusLine(request.httpVersion, 200, "OK");
    response.write("ok");
  } else {
    response.setStatusLine(request.httpVersion, 302, "Moved Temporarily");
    let url = new URL(params.get("redirect_uri") || params.get("default_redirect"));
    url.searchParams.set("access_token", "here ya go");
    response.setHeader("Location", url.href);
  }
}