<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic How to get out of OAuth2 invalid key not forwarding to a redirect-uri? in Dropbox API Support &amp; Feedback</title>
    <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/How-to-get-out-of-OAuth2-invalid-key-not-forwarding-to-a/m-p/243724#M13623</link>
    <description>&lt;P&gt;(also posted on&amp;nbsp;&lt;A href="https://stackoverflow.com/questions/46441051/is-it-possible-to-catch-a-dropbox-oauth2-authentication-error-in-the-parent-wind" target="_self"&gt;Stackoverflow&lt;/A&gt;)&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm using oauth2 client-side to authenticate users on my application and am stuck on handling errors, case in point being an invalid key. &amp;nbsp;I'm opening a popup which upon successful auth redirects to my parent-url (loading the parent page in the popup) and passing back the oauth token to the parent).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If oauth2 fails for any reason, there is no redirect and I'm stuck in the popup. So I was wondering whether there was any way to actively manage this error. Currently I'm doing this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;function (window, rJS, RSVP, promiseEventListener) {
  "use strict";

  var REQUEST_TIMEOUT = 10000;

  function getUrlParameter(name, url) {
    // retrieves url param
  }

  function uuid() {
    // returns an uuid
  }

  function setState() {
    var state = uuid();
    window.sessionStorage.setItem("state", state);
    return state;
  }

  function getState() {
    return window.sessionStorage.getItem("state");
  }

  rJS(window)

    .ready(function () {
      return this.initializeDropboxConnection();
    })
    .declareMethod("getDropboxConnect", function (my_url, my_name, my_config) {
      var popup;
      var popup_resolver;
      var resolver = new Promise(function (resolve, reject) {
        popup_resolver = function resolver(href) {
          var test = getUrlParameter("state", href);

          if (test &amp;amp;&amp;amp; getState() === test) {
            window.sessionStorage.setItem("state", null);
            resolve({
              "access_token": getUrlParameter("access_token", href),
              "uid": getUrlParameter("uid", href),
              "type": getUrlParameter("token_type", href)
            });
          } else {
            reject("forbidden");
          }
        };

        popup = window.open(my_url, my_name, my_config);
        popup.opener.popup_resolver = popup_resolver;
        return promiseEventListener(popup, "load", true);
      });

      return new RSVP.Queue()
        .push(function () {
          return RSVP.any([
            resolver,
            RSVP.delay(REQUEST_TIMEOUT)
          ]);
        })
        .push(function (my_ouath_dict) {
          if (my_ouath_dict) {
            return my_ouath_dict;
          }
          popup.close();
          throw "You type too slow... or your key isn't valid";
        });
    })

    .declareMethod("setDropboxConnect", function (my_client_id) {
      return this.getDropboxConnect(
        "https://www.dropbox.com/1/oauth2/authorize?" +
          "client_id=" + my_client_id +
          "&amp;amp;response_type=token" +
          "&amp;amp;state=" + setState() +
          "&amp;amp;redirect_uri=" + window.location.href,
        "",
        "width=480,height=480,resizable=yes,scrollbars=yes,status=yes"
      );
    })

    .declareMethod("initializeDropboxConnection", function () {
      // oauth popup will open same page and we will end up here, too
      // but when inside the popup, the opener must be set
      if (window.opener === null) {
        return;
      }

      // window.opener returns ref to window that opened this window
      // https://developer.mozilla.org/en-US/docs/Web/API/Window/opener
      // this passes the token to the promise waiting above
      return window.opener.popup_resolver(
        window.location.hash.replace("#", "?")
      );
    });

}(window, rJS, RSVP, promiseEventListener));&lt;/PRE&gt;&lt;P&gt;so after 15 seconds I force-close and assume something went wrong. Not really an optimal solution so I was wondering whether there is anything available to redirect in case of error and maybe pass an error token, so the application can handle.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Thanks!&lt;/P&gt;</description>
    <pubDate>Wed, 29 May 2019 09:19:04 GMT</pubDate>
    <dc:creator>frequent</dc:creator>
    <dc:date>2019-05-29T09:19:04Z</dc:date>
    <item>
      <title>How to get out of OAuth2 invalid key not forwarding to a redirect-uri?</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/How-to-get-out-of-OAuth2-invalid-key-not-forwarding-to-a/m-p/243724#M13623</link>
      <description>&lt;P&gt;(also posted on&amp;nbsp;&lt;A href="https://stackoverflow.com/questions/46441051/is-it-possible-to-catch-a-dropbox-oauth2-authentication-error-in-the-parent-wind" target="_self"&gt;Stackoverflow&lt;/A&gt;)&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm using oauth2 client-side to authenticate users on my application and am stuck on handling errors, case in point being an invalid key. &amp;nbsp;I'm opening a popup which upon successful auth redirects to my parent-url (loading the parent page in the popup) and passing back the oauth token to the parent).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If oauth2 fails for any reason, there is no redirect and I'm stuck in the popup. So I was wondering whether there was any way to actively manage this error. Currently I'm doing this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;function (window, rJS, RSVP, promiseEventListener) {
  "use strict";

  var REQUEST_TIMEOUT = 10000;

  function getUrlParameter(name, url) {
    // retrieves url param
  }

  function uuid() {
    // returns an uuid
  }

  function setState() {
    var state = uuid();
    window.sessionStorage.setItem("state", state);
    return state;
  }

  function getState() {
    return window.sessionStorage.getItem("state");
  }

  rJS(window)

    .ready(function () {
      return this.initializeDropboxConnection();
    })
    .declareMethod("getDropboxConnect", function (my_url, my_name, my_config) {
      var popup;
      var popup_resolver;
      var resolver = new Promise(function (resolve, reject) {
        popup_resolver = function resolver(href) {
          var test = getUrlParameter("state", href);

          if (test &amp;amp;&amp;amp; getState() === test) {
            window.sessionStorage.setItem("state", null);
            resolve({
              "access_token": getUrlParameter("access_token", href),
              "uid": getUrlParameter("uid", href),
              "type": getUrlParameter("token_type", href)
            });
          } else {
            reject("forbidden");
          }
        };

        popup = window.open(my_url, my_name, my_config);
        popup.opener.popup_resolver = popup_resolver;
        return promiseEventListener(popup, "load", true);
      });

      return new RSVP.Queue()
        .push(function () {
          return RSVP.any([
            resolver,
            RSVP.delay(REQUEST_TIMEOUT)
          ]);
        })
        .push(function (my_ouath_dict) {
          if (my_ouath_dict) {
            return my_ouath_dict;
          }
          popup.close();
          throw "You type too slow... or your key isn't valid";
        });
    })

    .declareMethod("setDropboxConnect", function (my_client_id) {
      return this.getDropboxConnect(
        "https://www.dropbox.com/1/oauth2/authorize?" +
          "client_id=" + my_client_id +
          "&amp;amp;response_type=token" +
          "&amp;amp;state=" + setState() +
          "&amp;amp;redirect_uri=" + window.location.href,
        "",
        "width=480,height=480,resizable=yes,scrollbars=yes,status=yes"
      );
    })

    .declareMethod("initializeDropboxConnection", function () {
      // oauth popup will open same page and we will end up here, too
      // but when inside the popup, the opener must be set
      if (window.opener === null) {
        return;
      }

      // window.opener returns ref to window that opened this window
      // https://developer.mozilla.org/en-US/docs/Web/API/Window/opener
      // this passes the token to the promise waiting above
      return window.opener.popup_resolver(
        window.location.hash.replace("#", "?")
      );
    });

}(window, rJS, RSVP, promiseEventListener));&lt;/PRE&gt;&lt;P&gt;so after 15 seconds I force-close and assume something went wrong. Not really an optimal solution so I was wondering whether there is anything available to redirect in case of error and maybe pass an error token, so the application can handle.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 29 May 2019 09:19:04 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/How-to-get-out-of-OAuth2-invalid-key-not-forwarding-to-a/m-p/243724#M13623</guid>
      <dc:creator>frequent</dc:creator>
      <dc:date>2019-05-29T09:19:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to get out of OAuth2 invalid key not forwarding to a redirect-uri?</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/How-to-get-out-of-OAuth2-invalid-key-not-forwarding-to-a/m-p/243848#M13631</link>
      <description>Unfortunately there isn't a good way to catch these errors, but I'll pass this along as a feature request.</description>
      <pubDate>Wed, 27 Sep 2017 18:03:22 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/How-to-get-out-of-OAuth2-invalid-key-not-forwarding-to-a/m-p/243848#M13631</guid>
      <dc:creator>Greg-DB</dc:creator>
      <dc:date>2017-09-27T18:03:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to get out of OAuth2 invalid key not forwarding to a redirect-uri?</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/How-to-get-out-of-OAuth2-invalid-key-not-forwarding-to-a/m-p/243975#M13648</link>
      <description>&lt;P&gt;Thanks for the info&amp;nbsp;and feature request &lt;img class="lia-deferred-image lia-image-emoji" src="https://www.dropboxforum.com/html/@FBF7D2AB59A0D6E861EBF6A36F93B7E2/emoticons/1f642.png" alt=":slightly_smiling_face:" title=":slightly_smiling_face:" /&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Sep 2017 07:46:22 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/How-to-get-out-of-OAuth2-invalid-key-not-forwarding-to-a/m-p/243975#M13648</guid>
      <dc:creator>frequent</dc:creator>
      <dc:date>2017-09-28T07:46:22Z</dc:date>
    </item>
  </channel>
</rss>

