Not able to get into callback after salesfore successful authentication using forcejs hybrid app

406 Views Asked by At

I have followed this blog and using forcejs plugin to make salesforce authentication in my ionic hybrid app. I am able to login and in popup URL (after redirection to callback) i can see the access token. But when popup come to callback url it does not close automatically and also my callback function is not being called.And i am not able to use the authentication result.

  let appId = 'consumer_key';
  let loginURL = 'https://login.salesforce.com/';
  let oauthCallbackURL = 'http://localhost:8100/callback';


  let oauth = OAuth.createInstance(appId, loginURL, oauthCallbackURL);
  console.log('=============oauth: ', oauth)

  oauth.login().then(oauthResult => {
          //can not get here after authentication
          DataService.createInstance(oauthResult);
          console.log("Logged Into Salesforce Successfully");
  });
1

There are 1 best solutions below

2
On BEST ANSWER

Use http://localhost:8100/oauthcallback.html as callback

and om the root of your application, create the oauthcallback.html

<html>
  <body>
   <script>
     var event = new CustomEvent("oauthCallback", {'detail': 
     window.location.href});
     window.opener.document.dispatchEvent(event);
     window.close();
  </script>
 </body>