如何在使用Google App Engine作为后端的Chrome扩展程序中实现用户身份验证? [英] How do I implement user authentication in a Chrome Extension using Google App Engine as backend?

查看:95
本文介绍了如何在使用Google App Engine作为后端的Chrome扩展程序中实现用户身份验证?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是后续我的上一个问题



我正在使用Chrome扩展程序 http:/ /ting-1.appspot.com/ 将书签页保存到Google App Engine后端。看看Chrome网上商店,我发现扩展程序有一个添加到铬按钮。由于我的扩展需要与后端进行通信(因此用户必须有一个gmail帐户才能使用此扩展名),我如何在扩展中指明使用用户名(添加扩展名的人的Gmail地址)来编写用他的用户ID书签到谷歌应用程序引擎?我的理解存在差距,我似乎在文档中找不到与此问题有关的任何内容。我的 background.html 如下。
$ b

background.html

 < HTML> 
< script>
chrome.browserAction.onClicked.addListener(function(tab){
chrome.tabs.getSelected(null,function(tab){

//发送请求到内容脚本。
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)*)
//});移动结束以获取变量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); $ b $ (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>


解决方案

您的扩展程序需要将用户发送到您的应用程序登录,以便设置适当的cookie,并且您的扩展程序可以作为用户进行身份验证。 Chrome to Phone扩展程序可以执行此操作,并且您可以检查其来源查看详情。


This is a follow up to my previous question.

I am working on a Chrome extension http://ting-1.appspot.com/ that saves the bookmarked page to Google App Engine backend. Looking at the Chrome web store I see that extensions have an "add to chrome" button. Since my extension requires communication with the backend (so the user must have a gmail account to use this extension) how do I indicate in the extension to use the username (the gmail address of the person who added the extension to Chrome) to write the bookmark to google app engine with his user id? I have a gap in my understanding and I don't seem to find anything related to this question in the documentation. My background.html is 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>

解决方案

Your extension needs to send the user to your app to sign in, so that the appropriate cookies will be set and your extension can authenticate as the user. The Chrome to Phone extension does this, and you can examine its source to see how.

这篇关于如何在使用Google App Engine作为后端的Chrome扩展程序中实现用户身份验证?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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