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

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

问题描述

我有一个 Chrome 扩展程序,它请求用户使用 chrome.identity.getAuthToken 路由登录.这工作正常,但当您登录时,您只能使用您在 Chrome 中拥有帐户的用户.

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.

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

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.

我可以使用一个帐户登录 Chrome,使用第二个帐户登录 Gmail,但我没有在扩展程序中进行选择.

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.

这可能吗?

推荐答案

不要使用 chrome.identity.getAuthToken 对用户进行身份验证,而是自己实现 OAuth 部分.

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

您可以使用库来帮助您,但我上次尝试使用最有用的库(Google API 客户端)时无法在 Chrome 扩展程序上运行.

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.

查看 Google OpenID Connect 文档以了解更多信息.最后,您要做的就是将用户重定向到 OAuth URL,使用您的扩展程序获取 Google 的答案(授权码),然后将授权码转换为访问令牌(这是一个简单的 POST 调用).

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

由于 Chrome 扩展程序无法重定向到网络服务器,因此您可以使用已安装的应用程序重定向 URI: urn:ietf:wg:oauth:2.0:oob.有了这个,Google 将显示一个包含授权代码的页面.

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.

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

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天全站免登陆