2

When I try to redirect users using force:navigateToURL and i specify a redirecturi which is within my community, it seems to ignore the external reference, and treat it as a community page. For Example:

var urlEvent = $A.get("e.force:navigateToURL");
    urlEvent.setParams({
          "url": 'https://www.3rdPartyWebSite.ca/potato?
otherpotato=1&potatotwo=2
&redirect_uri=https://MyCommunityURL.force.com/something/s/&state=something'
        });
    urlEvent.fire();

I am redirected to :

https://MyCommunityURL.force.com/something/s/&state=something

since this page doesnt exist, well, the user is not redirected anywhere. threfore I am forced to use window.open('url').

Is there a way to properly handle the redirection using force:navigateToURL?

FYI: note that to reproduce, you must replace MyCommunityUrl with "Your community Url"

0

2 Answers 2

0

It looks like the component does not handle several scenarios for already logged in users when adding community Urls as redirect parameters.

I thought that maybe encoding the url would have solved the Issue:

var encodedUrl = encodeURIComponent(url);

However, the underlying issue remains. The only working scenario was by encoding the redirect_uri parameter

    var url = 'https://www.3rdPartyWebSite.ca/potato?'+
        '&redirect_uri='+encodeURIComponent(redirect_uri)+
        '&state=something';

to succesfully redirect to my community home page.

The documentation mentions the following:

redirect_uri—URI to redirect the user to after approval. This URI must match one of the values in the Callback URL field in the connected app definition; otherwise, the approval fails. This value must be URL encoded.

therefore, to avoid any issues with redirection, this variable MUST be URL Encoded.

-1

I Just copied your code and tested; And it was working as expected.

But later I replicated issue and found that it's happening only if you pass your current community url as redirect_uri.

But it's weird, it's not expected behavior. I just read the doc for this component (https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/ref_force_navigateToURL.htm) multiple times and got stuck here- "do the right thing".

mailto:, tel:, geo:, and other URL schemes are supported for launching external apps and attempt to “do the right thing.” However, support varies by mobile platform and device. mailto: and tel: are reliable, but we recommend that you test any other URLs on a range of expected devices.

So, my assumption is this component works with only well written URL. For example, redirect uri does not seem ok; there should not be & just after /; usually parameters starts with ?

redirect_uri=https://MyCommunityURL.force.com/something/s/&state=something

So I just replaced this parameter as:

redirect_uri=https://MyCommunityURL.force.com/something/s?state=something

And it's working now as expected.

Lightning Component:

 <aura:component implements="forceCommunity:availableForAllPageTypes" access="global" >
    <lightning:button onclick="{!c.redirect}" label="redirect"> </lightning:button> 
</aura:component>

Controller:

({
    redirect : function(component, event, helper) {
        var urlEvent = $A.get("e.force:navigateToURL");
        urlEvent.setParams({
              "url": 'https://www.3rdPartyWebSite.ca/potatootherpotato=1&potatotwo=2&redirect_uri=https://MyCommunityURL.force.com/something/s?state=something'
            });
        urlEvent.fire();
    }
})

And it's redirected to:

enter image description here

5
  • You are right ...I was able to replicate the issue...and found root cause as well....let me update my answer!
    – Ayub
    Mar 30, 2018 at 19:08
  • I don't know about backend process of this component but tried lot to impress you! You guys are motivation and would not like to get downvote from you:)
    – Ayub
    Mar 30, 2018 at 19:23
  • the thing is that changing the declarative simbol of the first parameter from ? to & is not accespted by the OAUTH2 provider, and returns a 404 =( . unfortunately, this does not fix the underlying issue. Additioanlly, redirect_uri is as valid of a parameter as any other.
    – glls
    Mar 30, 2018 at 19:26
  • Sorry, but the '?' is a hierachical identifier that cannot be ranomly changed or removed as per RFC standards and serves a very specific purpose. If in your answer you propose to change this just for the sake of making the redirection work, it is not really an answer...
    – glls
    Mar 30, 2018 at 20:26
  • And who deleted my last comment?
    – Ayub
    Apr 2, 2018 at 14:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .