The following works fine for me in Android:
loginFacebook(): Promise<any> {
return new Promise((resolve, reject) => {
if (this.platform.is('cordova')) {
var browserRef = this.inAppBrowser
.create(`https://www.facebook.com/v2.9/dialog/oauth?client_id=${CLIENT_ID}&redirect_uri=${BASE_URL}/callback&response_type=token&scope=email`, "_blank", "location=no,clearsessioncache=yes,clearcache=yes");
const exitSubscription: Subscription = browserRef.on("exit").subscribe((event) => {
console.error("The Facebook sign in flow was canceled");
reject(new Error("The Facebook sign in flow was canceled"));
});
browserRef.on("loadstart").subscribe((event) => {
console.log(event);
if ((event.url).indexOf(`${BASE_URL}/callback`) === 0) {
console.log(event.url);
exitSubscription.unsubscribe();
browserRef.close();
var responseParameters = ((event.url).split("#")[1]).split("&");
var parsedResponse = {};
for (var i = 0; i < responseParameters.length; i++) {
parsedResponse[responseParameters[i].split("=")[0]] = responseParameters[i].split("=")[1];
}
if (parsedResponse["access_token"] !== undefined && parsedResponse["access_token"] !== null) {
console.log(parsedResponse);
resolve(parsedResponse);
} else {
console.error("Problem authenticating with Facebook");
reject(new Error("Problem authenticating with Facebook"));
}
}
});
} else {
console.error("loadstart events are not being fired in browser.");
reject(new Error("loadstart events are not being fired in browser."));
}
});
}
Obviously it doesn’t work in Browser because of this: https://github.com/apache/cordova-plugin-inappbrowser#browser-quirks-1