登录网站和Chrome扩展程序

问题描述:

我们有一个文件共享服务, http://ge.tt ,以及一些Chrome扩展程序.其中之一为Gmail添加了更多功能.

We have a file sharing service, http://ge.tt, and a few extensions for Chrome. One of them which adds extra capabilities to Gmail.

在此扩展程序中,我们要求用户在使用该扩展程序之前登录Ge.tt.由于他们已经登录了Ge.tt,因此不必再次登录就很好了,这会使一些用户误解它的工作原理.

In this extension we ask users to login to Ge.tt before they are able to use the extension. Since they are already logged in on Ge.tt it would be great that they didn't have to log in again, and it causes some users to misunderstand how it works.

解决这个问题的一种好方法是什么?其他人有同样的问题吗?

What would be a good way to go around and tackle this problem? Does others have the same issue?

您可以简单地从扩展名向仅用户页面发出HTTP请求,以查看它们是否已登录.诸如 ge.tt/my-profile-ping ,如果用户已登录,则返回 1 ,否则返回 0 .

You can simply make an HTTP request from the extension to the user-only page to see if they are logged in. Something like ge.tt/my-profile-ping which returns 1 if user is logged in, 0 otherwise.

扩展共享与浏览器相同的cookie,因此您只需要测试它们是否已登录并继续在扩展中显示仅登录的数据即可.

Extensions share the same cookies the browser does, so you just need to test if they are logged in and continue displaying logged-in-only data in your extension.

此外,别忘了在扩展清单中启用对域名ge.tt和www.ge.tt的请求,也可能对https版本(如果尚未启用)启用请求.

Also, don't forget to enable requests in your extension manifest for domain ge.tt, and www.ge.tt, and probably the https version also (if you haven't already)

您的 manifest.json 中类似的内容:

...
"permissions": [ "http://ge.tt/*", "https://ge.tt/*", "http://www.ge.tt/*", "https://www.ge.tt/*" ]
...