function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Timur KhayalievTimur Khayaliev 

Native iOS app. How to pass authorization token into Webview for a community users?

We created a simple iOS native app, which should allow users to login into SF once and then open Lightning community app in a Webview. For this purposes we have below steps:
1. User launch the mobile app;
2. App calls Mobile SDK, which redirects to community login page, where user enters login and password; That allows us to get and refresh session token if this is required.
3. We get an authorization token and passing community URL + token into WebView.
4. We tried to pass authorization token as a parameter like:

let request = try! URLRequest(url: URL(string: "<Link to community page>")!, method: .get, headers: ["Authorization" : "Bearer \(token!)"])
or using frontoor.jsp.

both ways works fine when I try to open classic SF page or application. But when I try to open Community page it asks login again. So that means that those ways does not work with a community pages.
So how can I pass authorization token to a Webview for a community users? Any help would be appreciated! Thanks!
Anil PunjabiAnil Punjabi
I have the same question -- were you able to find a solution?
chrisx01chrisx01
any solution ? I get the same now
umair bhattyumair bhatty
Any solution on the above problem as I am also facing the same issue the salesforce admin pages are opening on the mobile app but the Salesforce community pages are not open each timing it requires to log in again although the user is already logged in through Salesforce SDK.

Kindly let me know no what to do in order to make the community pages open on the app without assigning for login again
Umang LahaneUmang Lahane
I have the same query -- Anyone found any solution for this problem?
chrisx01chrisx01

use the frontdoor url and call VF Page which redirect to SFDC Commnunity 

an VF page 
<apex:page controller="xxx " action="{!redirect}">
</apex:page>
and a apex class

CommunityURL__c communityURL = CommunityURL__c.getValues('CommunityURL');
if (communityURL!=null) {
retURL = new PageReference(communityURL.CommunityURL__c);
retURL.getHeaders().put('Authorization', 'Bearer ' + UserInfo.getSessionId() );
retURL.setRedirect(true);
}

Johnny BaillargeauxJohnny Baillargeaux
Hi,
I have the same concern also with a community page. Did anyone found the solution or at least confirm this is a limitation because it's a community page?
Thanks :)
chrisx02chrisx02

this is new:

https://www.salesforce.com/blog/2019/01/introducing-mobile-publisher-community-cloud.html
so see this :

use the frontdoor url and call VF Page which redirect to SFDC Commnunity 
an VF page 
<apex:page controller="xxx " action="{!redirect}">
</apex:page>
and a apex class
CommunityURL__c communityURL = CommunityURL__c.getValues('CommunityURL');
if (communityURL!=null) {
retURL = new PageReference(communityURL.CommunityURL__c);
retURL.getHeaders().put('Authorization', 'Bearer ' + UserInfo.getSessionId() );
retURL.setRedirect(true);
}

Johnny BaillargeauxJohnny Baillargeaux
Hi,

Actually, I set the session ID this way to the header but I am still prompted to login:
 
<WebView
          onLoadStart={() => this.showSpinner()}
          onLoad={() => this.hideSpinner()}
          source={
            this.state.url == null
              ? {
                  html:
                    '<h1>Input parameters are missing</h1>',
                }
              : {
                  uri: this.state.url,
                  headers: {Authorization: 'Bearer ' + this.state.token},
                }
          }
        />
      </View>
this.state.url is the community URL
this.state.token is a valid token of course.

Basically, I do have a parent app built with Swift on top of the salesforce mobile sdk. I created a child app with react native with a webview to login as a community user and I expect to pass the token from the parent app to the child and then to the webview but everything works fine except this part. Not sure to understand the link with the frontdoor page, to be honest.

Thanks