Redirect the Chrome extension popup.html page to a URL for Oauth

六眼飞鱼酱① 提交于 2021-02-10 15:40:44

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!