Login to Chrome extension with a Google user other than the one in use by Chrome

后端 未结 1 440
逝去的感伤
逝去的感伤 2020-12-06 06:36

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

相关标签:
1条回答
  • 2020-12-06 07:16

    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.

    0 讨论(0)
提交回复
热议问题