问题
Is it possible to redirect the popup Html of a chrome extension to a remote URL?
I'm looking into this scenario for the purpose of OAuth. When a user clicks on the "Login with FB" button,
I want the Html page of the chrome extension to redirect to: https://www.facebook.com/dialog/oauth?client_id={app-id}&redirect_uri={redirect-uri}
so that the user is prompted to log in.
Is this the right approach to do authentication in a Chrome extension anyway?
回答1:
Popups are very.. fragile. They are too easy to close, the user can't use password managers to fill the form etc. They are also very size-constrained. Maybe not the best idea.
You can, instead, use chrome.windows
to create a login-type window:
chrome.windows.create({
url: "YourLoginURL",
type: "popup",
focused: true
});
However, all that is not the "native" way to do OAuth in Chrome extensions.
The native way is to use chrome.identity API, specifically chrome.identity.launchWebAuthFlow.
As an added bonus, it allows you to use a virtual https:
callback URL, which is the most widely supported option, without having to own a domain.
来源:https://stackoverflow.com/questions/25769964/redirect-the-chrome-extension-popup-html-page-to-a-url-for-oauth