So basically , I am building a Chrome Extension using vanilla javascript for outlook. In that extension I have to fetch the email of currently logged in user. I have registered my app on Azure , got the client ID , added the neccessary permissions like openId , profile , User.Read , User.Mail in app , added neccessary scopes but Still I am not getting the identity token.
**
manifest.json**
{
"manifest_version": 3,
"name": "Plugin for Outlook",
"description": "Base Level Extension",
"version": "1.0",
"action": {
"default_popup": "popup/popup.html",
"default_icon": "images/logo.png"
},
"permissions": [
"contextMenus",
"activeTab",
"scripting",
"storage",
"identity"
],
"host_permissions": [
"https://graph.microsoft.com/*",
"https://ccqrs034g7.execute-api.us-east-1.amazonaws.com/*"
],
"background": {
"service_worker": "background.js"
},
"oauth2": {
"client_id":"my id",
"scopes": [
"openid", "email", "profile" , "https://graph.microsoft.com/profile"
]
},
"content_scripts":[
{
"matches": ["<all_urls>"],
"js":["contentScript.js"]
}
]
}
background.js
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
console.log("hello");
if (message.action === "getEmail") {
chrome.identity.getAuthToken({ interactive: true }, function (token) {
if (chrome.runtime.lastError || !token) {
console.error(chrome.runtime.lastError);
return;
}
fetch("https://graph.microsoft.com/v1.0/me", {
headers: {
Authorization: "Bearer " + token,
},
})
.then((response) => response.json())
.then((userInfo) => {
const data = message.data;
console.log(data);
// Sending Data to backend
})
.catch((error) => console.error(error));
});
}
return true;
});