Tip #706: Passing arguments to the webresource does not work after authentication

Fallen godWe are all mortals, after all. I just witnessed a rare occassion when even Tanguy “The XRM Toolbox” Touzard needed a helping hand from none other than Andrii “Khohol” Butenko.

Tanguy

I’m working on a really simple integration where an external app needs to open a webresource with parameters passed in data url argument:

https://qwerty.crm4.dynamics.com/WebResources/foo_/cti/index.html?data=phonenumber%3d0123456789%26service%3dadv

as mentioned in the SDK, parameters are encoded in data url argument. The problem is if I open this url before being authenticated to CRM Online, I’m redirected to the authentication page then redirected to the requested page. Problem is that the url is altered, as the “?” character is replaced with %3F

https://qwerty.crm4.dynamics.com/WebResources/foo_/cti/index.html%3Fdata=phonenumber%3d0123456789%26service%3dadv

Thus, the page does not see the arguments passed in data.

Is this a known problem?

Andrii

I experienced the same problem and found a workaround: just add the following script to onload event:

var params = GetGlobalContext()
             .getQueryStringParameters();

if (typeof params.data == "undefined") {
  var currentUrl = window.location.href;

  if (currentUrl.indexOf("%3F") != -1) {
    currentUrl = currentUrl.replace("%3F", "?");
    window.location.href = currentUrl;
    return;
  }
}
Tweet about this on TwitterShare on Facebook0Share on Google+0

4 thoughts on “Tip #706: Passing arguments to the webresource does not work after authentication

  1. Paul Way says:

    Instead of refreshing the page, you can parse the URL getting your specific parameter values.

    Also, using the 1Password app on the iPhone makes accessing a web resource really easy. The app can save your credentials and reduces the clicks greatly.

    • I’ll leave to Andrii to defend his approach 🙂

      Not sure what 1Password has got anything to do with it. 1Password (or LastPass) would simply enter credentials on your behalf. You’re still going to get a redirect that would encode the question mark.

      • Paul Way says:

        Yeah, the point of 1Password or LastPass is just convenience for the mobile user. You still get the ADFS prompt, but when you’re on mobile, its nice to use a password manager to speed up the process. With 1Password (and others), you can store the web resource URL and credentials as a favorite to quickly gain access.

        As for Andrii’s approach, the reload is a fine way to do it. One caveat is that it refreshes the page unnecessarily. You can directly access the data parameter without the refresh by using something like:

        var GetUrlParameter = function (name) {
        name = name.replace(/[\[]/, “\\[“).replace(/[\]]/, “\\]”);
        var regexS = “[\\?&]” + name + “=([^&#]*)”,
        regex = new RegExp(regexS),
        url = window.location.href.toLowerCase().replace(‘%3f’, ‘?’),
        results = regex.exec(url);

        if (results === null) {
        return “”;
        } else {
        return results[1];
        }
        };

        Calling the function with:
        var paramData = GetUrlParameter(‘data’);

Leave a Reply

Your email address will not be published. Required fields are marked *