@Override
    public void handle(HttpExchange httpExchange) throws IOException {
      Map<String, String> params =
          EncodingHelper.parseKeyValueList(httpExchange.getRequestURI().getQuery(), '&', true);

      if (params == null
          || !params.containsKey(STATUS_PARAM_NAME)
          || !params.containsKey(DATA_PARAM_NAME)
          || !params.get(STATUS_PARAM_NAME).equals(STATUS_SUCCESS)) {

        httpExchange.sendResponseHeaders(400, -1);
        if (authCodeCallback != null) {
          authCodeCallback.onAuthCodeReceived(null, params);
        }
        return;
      }

      code = params.get(DATA_PARAM_NAME);

      // setup response headers
      Headers headers = httpExchange.getResponseHeaders();
      headers.add("Content-Type", "text/html");
      httpExchange.sendResponseHeaders(200, 0);

      // send browser response
      InputStream input = getClass().getClassLoader().getResourceAsStream("auth-response.html");
      OutputStream output = httpExchange.getResponseBody();
      ByteStreams.copy(input, output);
      output.close();
      input.close();

      // raise the notification for the code
      if (authCodeCallback != null) {
        authCodeCallback.onAuthCodeReceived(code, params);
      }
    }