The particular authentification method that I’m using in my app requires the inAppBrowser to open an external URL which will contain URL parameters that need to be passed into the app.
browser.on('loadstop').subscribe(
data => {
let url = data.url;
(here you do whatever you want with the url) alert(url);
)}
}
Dunno if this helps, for me i used it to grab URL and use a condition when the user visited a specific URL to trigger a function. Maybe also you can manipulate the URL and grab the params you need.
of course you need to declare in your constructor “private iab: InAppBrowser”, and import in your declarations import {InAppBrowser} from “@ionic-native/in-app-browser”
I have a similar issue, I fetching the url data on loadstop event, and on exit event I am calling a local service where I have to pass that fetched data. But in the exit event I am not able to access the url data. I have no idea why this is happening. Below is my code
public office365Login(){
debugger;
let browser = new InAppBrowser("https://login.microsoftonline.com/" +SvcConstsService.TENANT_ID+
"/oauth2/authorize?response_type=code&client_id=" + SvcConstsService.CLIENT_ID +
"&resource=" + SvcConstsService.GRAPH_RESOURCE +
"&redirect_uri=" + SvcConstsService.REDIRECT_URL,'_blank','location=no');
browser.on("loadstop").subscribe(function(event){``
this.code_token=event.url.split('?')[1].split('&')[0].replace('code=','');
this.session_state=event.url.split('&')[1].replace('session_state=','');
console.log("code_token ",this.code_token);
console.log("session state ",this.session_state);
browser.close();
// code_token and session_state is the data I am getting from url
},err=>console.log(err)
);
browser.on("exit").subscribe(()=>{
// the fetched data is passed to the below method, but not able to access it.
this.getUserDetails();
});
}
On loadstop() event if you are getting data from the url, then store that in local storage, and on exit event fetch that data from the local storage, and make a service call to the backend. This works for me.
You coul also change the loadstop handler to be an arrow function as on exit (and acually give a variable for the on at exit to make this more consistent):