Chrome Extension Manifest v3 MV3 authentication [closed]
H

1

10

I need to use Manifest version 3(MV3) to handle Google sign-ins on Chrome extensions. How could i go about this, given that it's only mentioned in the docs that it cannot be done?

Hurley answered 6/6, 2022 at 7:50 Comment(2)
Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer.Atp
for anyone struggling with this, here is the code for an example using chrome.identity to get token and then use it with google/youtube api github.com/sturm-dev/chrome-extension-google-authTussis
H
14

Currently, with manifest v3 we cannot use the google sign popup for authorizing users. We should be using chrome.identity API for authenticating the users with OAuth2 API services. I have used the google cloud platform to create the Oauth2 client id and token. Let me show you step by step process :

  1. Create a project with google cloud

  2. After creating the project you must create credentials for that project. Go to the credentials section and choose OAuth client ID
    enter image description here.

  3. Next step is to get your extension id which can be easily found on the chrome://extensions page enter image description here

  4. Now in "Create OAuth client id" section,choose “Chrome app” as the application type for the OAuth 2.0 client, and paste your extension ID into the Application ID field enter image description here

  5. After creating it, you will get the client_id which needs to be used in our manifest.json file.

"oauth2": {
        "client_id": "<YOUR_CLIENT_ID>.apps.googleusercontent.com",
        "scopes": []
      }
  1. To access the chrome.identity API in your chrome extension, add identity as in the permissions section

"permissions": [ "identity" ]

  1. Finally, you can trigger the API by using the following method

     chrome.identity.getAuthToken({ 'interactive': true }, function (token) {
        console.log(token);
      });

For further information , please checkout the article here

Highway answered 13/8, 2022 at 14:50 Comment(4)
For more information, see developer.chrome.com/docs/extensions/mv3/tut_oauthMonad
for anyone struggling with this, here is the code for an example using chrome.identity to get token and then use it with google/youtube api github.com/sturm-dev/chrome-extension-google-authTussis
Chrome.identity.getAuthToken gives only token, not refresh token. So how do I refresh the token after it has expired? @EmmaAlecrimMarlenamarlene
Is there any solution for Opera? This code gives Unchecked runtime.lastError: Function unsupported, which led me to find that "Opera only supports the launchWebAuthFlow() Method in this API" per their docs.Outherod

© 2022 - 2024 — McMap. All rights reserved.