-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.js
48 lines (42 loc) · 1.38 KB
/
background.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
var oauth = ChromeExOAuth.initBackgroundPage({
'request_url' : 'https://www.google.com/accounts/OAuthGetRequestToken',
'authorize_url' : 'https://www.google.com/accounts/OAuthAuthorizeToken',
'access_url' : 'https://www.google.com/accounts/OAuthGetAccessToken',
'consumer_key' : 'anonymous',
'consumer_secret' : 'anonymous',
'scope' : 'https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email',
'app_name' : 'Sample - OAuth Test'
});
var contacts = null;
function setIcon() {
if (oauth.hasToken()) {
chrome.browserAction.setIcon({ 'path' : 'img/icon-19-on.png'});
} else {
chrome.browserAction.setIcon({ 'path' : 'img/icon-19-off.png'});
}
};
function onContacts(text, xhr) {
contacts = JSON.parse(text);
chrome.tabs.create({ 'url' : 'contacts.html'});
};
function getContacts() {
oauth.authorize(function() {
console.log("on authorize");
setIcon();
var url = "https://www.googleapis.com/oauth2/v2/userinfo";
oauth.sendSignedRequest(url, onContacts, {
'parameters' : {
'alt' : 'json',
}
});
});
};
function logout() {
oauth.clearTokens();
setIcon();
};
setIcon();
chrome.browserAction.onClicked.addListener(getContacts);