登录和Chrome扩展程序练习中的身份验证 [英] Login & Authentication in Chrome Extension Practice

查看:109
本文介绍了登录和Chrome扩展程序练习中的身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发chrome扩展程序,并尝试实现身份验证方法(firebase).我对必须去的地方感到困惑,因为popup.html不允许内联脚本,这使其变得更加困难. 据我所知,有两个选项:

I'm working on a chrome extension and trying to implement an authentication method (firebase). I'm confused by what has to go where, since the popup.html doesn't allow inline script, it makes it a bit more difficult. As far as I see this there are 2 options:

  1. 从扩展名中呼叫外部页面(由我托管),在新标签页中打开,然后在此处处理登录.但是在这种情况下,扩展程序如何与登录页面通信?饼干?我需要在popup.js中进行确认

  1. Call external page (hosted by me) from the extension, open in new tab, handle login there. But in this case, how does the extension communicate with the login page? Cookies? I need the confirmation inside my popup.js

尝试在Chrome扩展程序弹出窗口中处理电子邮件/密码登录,这似乎更为复杂.我总是违反内容安全政策,有点烦人.我已经尝试过了,问题是一旦您关闭弹出窗口,它就会失去登录状态.

Try to handle Email/Password login in Chrome extension popup, which seems more complicated. I always violate the Content Security Policy, bit annoying. I tried this already, problem is once you close the popup, it looses the login state.

我已经进行了很多研究,但是到目前为止,还没有真正好的例子,其他问题也几乎没有得到回答.谢谢!

I researched already a lot, but there is no real good example so far, and other questions are barely answered. Thanks!

推荐答案

您可以尝试在弹出窗口中使用登录名/密码输入框,但在后台页面中运行实际的登录代码.您可以执行以下操作,将消息从弹出窗口发送到后台页面,或直接从弹出窗口发送消息:

You could try to have the login/password input boxes in the popup but run the actual login code in the background page. You can do that sending a message from the popup to the background page or directly from the popup using something like:

popup.html:

popup.html:

<input type="text" id="email">
<input type="password" id="password">

popup.js:

var email = document.getElementById("email").value;
var password = document.getElementById("password").value;

chrome.runtime.getBackgroundPage(function(bgPage){
    bgPage.performFirebaseLoginWithEmailAndPassword(email,password);
});

由于后台页面始终处于打开状态,因此在关闭弹出窗口时应保留登录状态.

Since the background page is always on, the login state should be preserved when the popup is closed.

这篇关于登录和Chrome扩展程序练习中的身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆