使用Chrome用户以外的Google用户登录Chrome扩展程序 [英] Login to Chrome extension with a Google user other than the one in use by Chrome

查看:402
本文介绍了使用Chrome用户以外的Google用户登录Chrome扩展程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Chrome扩展程序,要求用户使用chrome.identity.getAuthToken路由进行登录。此功能正常,但是当您登录时,您只能使用您在Chrome中拥有帐户的用户。



客户希望能够使用不同的Google登录帐户;而不是使用Chrome登录的帐户the.client@gmail.com,他们希望能够使用.client@company.com登录,该帐户也是有效的Google帐户。



我可以使用一个帐户登录Chrome,使用第二个帐户登录Gmail,但我无法选择在扩展程序中选择。



这可能吗? ,您只需自己实现OAuth部分即可。



您可以使用库来帮助您,但最后一次尝试使用最有用的库(Google API Client)将无法运行在Chrome扩展程序中。



查看 Google OpenID Connect

a>文档以获取更多信息。最后,您只需将用户重定向到OAuth网址,使用您的扩展程序获取Google的答案(授权码),然后将授权码转换为访问令牌(这是一个简单的POST调用)。



由于Chrome扩展程序无法重定向到Web服务器,因此您可以使用安装的应用程序重定向URI: urn:ietf:wg:oauth:2.0:oob 。使用此Google将显示包含授权码的页面。



只需使用您的扩展在本页中注入一些javascript代码即可获取授权码,关闭HTML页面,执行POST调用以获取用户的电子邮件。


I have a Chrome extension that requests a user to login using the chrome.identity.getAuthToken route. This works fine, but when you login you can only use the users that you have accounts in Chrome for.

The client would like to be able to login with a different Google account; so rather than using the.client@gmail.com, which is the account Chrome is signed in to, they want to be able to login using the.client@company.com, which is also a valid Google account.

It is possible for me to be logged in to Chrome with one account, and Gmail with a second account, and I do not get the option to choose in the extension.

Is this possible?

解决方案

Instead of authenticating the user using the chrome.identity.getAuthToken , just implement the OAuth part yourself.

You can use libraries to help you, but the last time I tried the most helpful library (the Google API Client) will not work on a Chrome extension.

Check out the Google OpenID Connect documentation for more info. In the end all you have to do is redirect the user to the OAuth URL, use your extension to get Google's answer (the authorization code) and then convert the authorization code to an access token (it's a simple POST call).

Since for a Chrome extension you cannot redirect to a web server, you can use the installed app redirect URI : urn:ietf:wg:oauth:2.0:oob. With this Google will display a page containing the authorization code.

Just use your extension to inject some javascript code in this page to get the authorization code, close the HTML page, perform the POST call to obtain the user's email.

这篇关于使用Chrome用户以外的Google用户登录Chrome扩展程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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