Use api for requesting user info

Found an api for requesting the email of the logged in user.
Let's see how that works. Also discovered that content scripts
cannot login a user that has to be done by a background script.
This commit is contained in:
Nils Norman Haukås 2016-08-14 20:01:44 +02:00
parent fcee0cb3d8
commit c1e46e36e1
3 changed files with 40 additions and 10 deletions

View file

@ -31,7 +31,7 @@ export class SettingsCtrl {
$scope.vm = this;
this.loadSettings()
this.startListeningForLogins()
}
loadSettings() {
@ -67,11 +67,19 @@ export class SettingsCtrl {
}
testLogin() {
debugger;
chrome.identity.getAuthToken({'interactive': true},
(token) => {
debugger;
})
if (typeof chrome === 'undefined') return; //do nothing
chrome.runtime.sendMessage({command: 'requestUserInfo'})
}
startListeningForLogins() {
chrome.runtime.onMessage.addListener(
(request, sender, sendResponse) => {
if (request.loginObj) {
this.$log.debug('listenForLogin() got a message from the extension')
this.$log.debug(request)
}
}
);
}
}

View file

@ -12,9 +12,7 @@ chrome.browserAction.onClicked.addListener(function (tab) {
});
function isMenuOpen(callback) {
chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
chrome.tabs.sendMessage(tabs[0].id, "isMenuOpen", callback);
});
messageExtension('isMenuOpen', callback);
}
function injectIframe(tab) {
@ -27,4 +25,28 @@ function injectIframe(tab) {
allFrames: true
});
});
}
/**
* Start listening for messages coming from the injected
* javascript.
*/
chrome.runtime.onMessage.addListener((msg) => {
if (msg.command === 'requestUserInfo') {
console.log('Extension got a command to retrieve user info');
chrome.identity.getProfileUserInfo((userInfo) => {
console.log(userInfo)
messageExtension({loginObj: userInfo})
});
}
});
function messageExtension(messageToSend, callback) {
chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
if (callback) {
chrome.tabs.sendMessage(tabs[0].id, messageToSend, callback);
} else {
chrome.tabs.sendMessage(tabs[0].id, messageToSend);
}
});
}

View file

@ -1,7 +1,7 @@
{
"name": "Tag you're it",
"description": "A browser tool for tagging words with exact definitions.",
"version": "1.0.4",
"version": "1.0.5",
"manifest_version": 2,
"icons": {
"16": "icon16.png",