Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Login & Authentication in Chrome Extension Practice

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. 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

  2. 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!

like image 616
ffritz Avatar asked Jun 10 '16 12:06

ffritz


People also ask

How can I login to my Gmail account?

On your computer, go to Gmail. Enter your Google Account email or phone number and password. If information is already filled in and you have to sign in to a different account, click Use another account. If you get a page that describes Gmail instead of the sign-in page, at the top right of the page, click Sign in.

What is the login process?

In general computer usage, logon is the procedure used to get access to an operating system or application, usually in a remote computer. Almost always a logon requires that the user have (1) a user ID and (2) a password.

What is the difference between signin and login?

Sign in happens when you enter username and password into a site to access the pages that are restricted. This is also referred to as membership. Log in is successful when your credentials (i.e username and password) match with what is already stored in database. This is called authentication.


1 Answers

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:

<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.

like image 176
Iván Nokonoko Avatar answered Sep 28 '22 08:09

Iván Nokonoko