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:
parent
fcee0cb3d8
commit
c1e46e36e1
3 changed files with 40 additions and 10 deletions
|
@ -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)
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
});
|
||||
}
|
|
@ -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",
|
||||
|
|
Loading…
Reference in a new issue