5

I am attempting to authenticate with Constant Contact via OAuth2 in a popup window. I am using $.postMessage to send the data between windows, and for the most part, it works beautifully.

My problem is with Safari. A normal request has a URL that looks like this:

https://example.com/oauth-v2/#access_token=xxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx&token_type=Bearer&expires_in=xxxxxxxxx

But while using Safari to make the request, the entire hash is cut off the URL and location.hash, window.location.hash, window.parent.location.hash are all empty.

The authentication flow is fairly standard:

  1. User clicks auth button
  2. Popup window to auth with Constant Contact
  3. Allow application
  4. List item
  5. Return to app site to capture token

Here's the javascript we're using to get the URL hash info

jQuery(document).ready(function ($) {
  $.extend({
    getQueryParameters: function (str) {
      return (str || document.location.search || document.location.hash)
        .replace(/(^\?)|(^\#)/, '')
        .split("&")
        .map(function (n) { return n = n.split("="), this[n[0]] = n[1], this }.bind({}))[0];
    }
  });
  $.receiveMessage(function (event) {
    $.postMessage($.getQueryParameters(), event.origin, event.source);
    setTimeout(function () {
      window.close()
    }, 5000);
  });
});

Is the missing hash a known bug in Safari? Should I be doing something else to get the info from Constant Contact? It works in every other browser so I would hate to re-write this part of the application.

n1stre
  • 5,856
  • 4
  • 20
  • 41
  • did you ever get this fixed, we have exactly the same problem.. http://stackoverflow.com/questions/34343828/oauth2-implicit-flow-token-removed-from-location-hash – otter606 Dec 18 '15 at 18:33
  • Unfortunately not. We ended up just documenting the exception for our customers and we never heard of any of them running into the issue. I guess there wasn't enough demand to justify spending a ton of time on it. Sorry I couldn't be of more help! – Channeleaton Dec 18 '15 at 22:54

0 Answers0