Obtaining a distinct user identifier in a chrome extension through OAuth is a straightforward process

As I utilize the identity permission in my manifest file, I employ

chrome.identity.getAuthToken( { 'interactive': true }, function( token )
in my JavaScript code to obtain the user's identification token.

Is there a method to acquire the unique user ID or email address without requesting additional permissions?

Answer №1

To retrieve the email address and a unique ID, you can utilize

chrome.identity.getProfileUserInfo()
. Ensure to include the identity.email permission along with identity. No OAuth2 token or network connection is necessary for this method.

Below is a basic extension that displays this data in the console of a background page:

manifest.json

{
  "manifest_version" : 2,

  "name" : "Identity Test",
  "version" : "0.1",

  "background": {
    "scripts": ["background.js"]
  },

  "permissions": [
    "identity",
    "identity.email"
  ]
}

background.js

chrome.identity.getProfileUserInfo(function(userInfo) {
  console.log(JSON.stringify(userInfo));
});

Alternatively, you can fetch user info by utilizing the Google API with an OAuth2 token. Make sure to specify both the profile and email scopes. If you opt for the Google API Client library, you can use

gapi.client.oauth2.userinfo.get()
. While this strictly adheres to your request of using OAuth and avoiding added permissions, it seems that
chrome.identity.getProfileUserInfo()
is likely what you need.

Answer №2

The permissions required to access certain information will be determined by the OAuth2 scopes specified in your manifest.json file.

For instance, if you have included Google Drive scope in your declaration, you will be able to make use of Google Drive's About GET method (refer to it here) to fetch the user's id and email address, along with a range of other information.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Digital clocks created with Javascript for educational purposes, each displaying a unique image array for K-12 students

I am on the lookout for a script that can run a digital clock in a web browser using unique images for each digit. I plan to create a 'Maarten Baas' inspired clock with the children in my technology and design class. The kids will take on the ro ...

Converting JSON to XML in Java while preserving attributes

When utilizing the org.json json library, converting from XML to JSON is straightforward. However, the conversion back to XML results in JSON attributes being converted into XML nodes: import org.json.JSONObject; import org.json.XML; public class Test { ...

The ngMessages validation feature in AngularJS fails to remove error messages from the CSS styling

Can anyone help me figure out why I keep getting a red color underline error even though there is no actual error and validation is successful? https://i.sstatic.net/AESLl.png I created my own directive to validate passwords and I am using Angular materi ...

Obtaining the previous element with aria-selected using Jquery Selector rather than the current one

I am currently utilizing Semantic UI React to design a dropdown menu for selecting countries. To access the values that are passed as attributes to a <div role=option />, I use the following method: handleSelectCountry = (e, props) => { con ...

Mastering the asynchronous nature of Node.js with async/await techniques

Is there a way to synchronize the creation of my customers' shopping cart and the insertion of items using a dynamically generated session id? It seems like the issue lies with the order in which the table (cart) is created. Could someone assist me wi ...

Guide on retrieving file information after transmitting it to another PHP file through Ajax

I have written code to upload a file and send it to a php page. I would like the response to be an array containing information about the uploaded file such as name, size, type, etc. I am using the "POST" method for uploading the file. Is this approach cor ...

Exploring the art of JSON interpretation within Highcharts

Below is an example snippet that utilizes static data: Highcharts.chart("container", { title: { text: "Highcharts pie chart" }, xAxis: { categories: [ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Ju ...

Is there a way to have my MUI Typography component display a unique image cursor when hovered over?

After some testing, I found that setting the cursor to cursor: pointer works perfectly fine. However, my goal is to use a custom image as a cursor. The image is saved in both my src and public folders, but I seem to be struggling with the syntax when using ...

Running both asynchronous and synchronous requests at the same time on Google Chrome

My device specifications are: Intel Core i3-2310M 2.10 GHz Operating System: Windows 7 Home Basic Browser Options: Google Chrome or Opera Server Configuration: Apache on 127.0.0.1 with CSP module (for InterSystems Caché® database system) When accessi ...

Combining and adding together numerous objects within an array using JavaScript

I'm looking to combine two objects into a single total object and calculate the percentage change between the two values. I'm encountering some difficulties while trying to implement this logic, especially since the data is dynamic and there coul ...

Creating a rotating wheel using JavaScript that is activated by a key press event

I need some help with implementing a keystroke event in this code so that the spinning wheel can start based on a key press, like the spacebar. Any suggestions on how to achieve this? I have found an event code for keystrokes in JavaScript: document.body. ...

How can the onclick attribute be modified in an HTML document?

I am looking to update the data-pro-bar-percent attribute of a progress bar from 80 to 100 when a specific link is clicked. The change in attribute needs to be as follows: data-pro-bar-percent="80" --> data-pro-bar-percent="100" This is the current HT ...

Having npm start is causing an error to be displayed

I am encountering an issue when I try to start 'npm' on my mean.js application. The error message is related to a missing file called '.csslintrc'. Below, I have included the terminal output as well as the snippet of code where the erro ...

Ways to retrieve an input field value without triggering form submission

I'm currently working on a payment form where users input the amount in a text field. I also have another text field on the same form that should automatically display the amount in words based on the user input. However, I'm struggling to figure ...

Implementing Vue.js click event behavior on a component within the template

Encountering an issue while developing Vue's template onclick event. Trying to open a module when clicking a file, I have looked at some samples with native code, but it does not quite fit into my code and I cannot reach the console. Here is my code: ...

Best practice for showcasing the output of an array in Javascript

My variables are defined in an array like this: const nbActions = 13; const sdgValues = ['1', '2', '5', '6', '3', '0', '2', '0', '0', '6', '0', & ...

The top scrolling behavior on click applies exclusively to the first set of Bootstrap 5 tabs

I am experiencing an issue with my HTML webpage that contains multiple BS5 Nav Tabs. The first tab is not functioning properly, while all the other tabs are working smoothly. When I click on the first BS5 Nav Tab, the page scrolls to the top with the addre ...

Monitoring inbound and outbound traffic in express middleware

I am in the process of incorporating a logger into my Express application. This logger needs to record both requests and responses (including status codes and body content) for each request made. My initial approach involves creating a middleware function ...

Combine the content from multiple text areas and submit it to another text area

****UPDATE**** Thanks to @JasonB, I was able to resolve the previous issue mentioned. Now, I have three additional textareas on the same form that should only appear when their respective checkboxes are clicked. How can I integrate this into my current sc ...

Create a roster of individuals who responded to a particular message

Can a roster be created of individuals who responded to a specific message in Discord? Message ID : '315274607072378891' Channel : '846414975156092979' Reaction : ✅ The following code will run: bot.on("ready", async () = ...