'manual FB login integration ( without SDK)
FB dialog gives me no feedback so that I can parse token from url and close it. Window event is stuck in onunload event.
The below code builds my FB url which I then open in Window.open function. But my token is never resolved or rejected because load is never fired.
buildUrlFb = () => {
let params = "fbloged=1";
return `https://www.facebook.com/v13.0/dialog/oauth?client_id=${FB_ID}&redirect_uri=${redirectUri}&state=${params}`;
};
popupWindow = (url, windowName, win, w, h) => {
const y = win.top.outerHeight / 2 + win.top.screenY - h / 2;
const x = win.top.outerWidth / 2 + win.top.screenX - w / 2;
return win.open(
url,
windowName,
`toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=${w}, height=${h}, top=${y}, left=${x}`
);
};
openFbDialog = async () => {
return new Promise((resolve, reject) => {
let uri = this.buildUrlFb();
let window01 = this.popupWindow(uri, "Sign in with Fb", window, 500, 500);
window01.addEventListener("load", (event) => {
try {
let uri02 = window01.location.href;
let token = this.getUrlParameter("code", uri02); // when the server will be handling the token
// console.log("pop up token", token);
resolve(token);
window01.close();
} catch (ex) {
console.log("ex", ex);
reject(null);
}
});
});
};
I tried to capture url token on load event, but for that I need to close pop up window and reopen it.
I want to basically capture/detect the redirect from facebook to my domain inside the pop up window.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
