How do I implement user authentication in a Chrome extension using the Google App Engine as a backend?

This is a continuation of my previous question .

I am working on the Chrome extension http://ting-1.appspot.com/ , which saves a bookmark with a bookmark in the Google App Engine backend. Looking at the Chrome Web Store, I see that the extensions have an β€œadd to chrome” button. Since my extension requires a connection with the backend (therefore, the user must have a gmail account to use this extension), how to specify in the extension to use the username (gmail address of the person who added the extension in Chrome) to write bookmarks to the Google engine with its identifier user? I have a gap in my understanding and I don't seem to find anything related to this issue in the documentation. My background.html below. Thanks.

background.html

 <html> <script> chrome.browserAction.onClicked.addListener(function(tab) { chrome.tabs.getSelected(null, function(tab) { // Send a request to the content script. chrome.tabs.sendRequest(tab.id, {action: "getDOM"}, function(response) { var firstParagraph = response.dom; console.log("background -- before *console.log(response.dom)*") console.log("this is *console.log(response.dom)*: " + response.dom) console.log("background -- after *console.log(response.dom)*") //}); moved to end to get the variable firstParagraph var formData = new FormData(); formData.append("url", tab.url); formData.append("title", tab.title); formData.append("pitch", firstParagraph); var xhr = new XMLHttpRequest(); xhr.open("POST", "http://ting-1.appspot.com/submithandlertest", true); xhr.onreadystatechange = function (aEvt) { if (xhr.readyState == 4) { if (xhr.status == 200){ console.log("request 200-OK"); chrome.browserAction.setBadgeText ( { text: "done" } ); setTimeout(function () { chrome.browserAction.setBadgeText( { text: "" } ); }, 2000); }else{ console.log("connection error"); chrome.browserAction.setBadgeText ( { text: "ERR" } ); } } }; xhr.send(formData); }); //chrome.tabs.sendRequest }); }); </script> </html> 
+6
source share
1 answer

Your extension must be sent to the user in the login application so that the appropriate cookies are set and your extension can authenticate as a user. The Chrome to Phone extension does this, and you can study its source to find out how.

+7
source

Source: https://habr.com/ru/post/899658/


All Articles