Skip to content

Commit

Permalink
fixed mixed to work with manifest_version=2
Browse files Browse the repository at this point in the history
  • Loading branch information
dwabyick committed Oct 22, 2012
1 parent bdc380b commit 31ee7a8
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 52 deletions.
3 changes: 2 additions & 1 deletion samples/mixed/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
"name": "Multi OAuth 2.0",
"version": "1.0",
"description": "OAuth 2.0 Extension Demo",
"manifest_version": 2,
"icons": {
"128": "icon128.png"
},
"browser_action": {
"default_title": "OAuth 2.0",
"default_icon": "icon128.png",
"popup": "popup.html"
"default_popup": "options.html"
},
"options_page": "options.html",
"content_scripts": [
Expand Down
56 changes: 5 additions & 51 deletions samples/mixed/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<head>
<title>OAuth 2.0 Options</title>
<script src="oauth2/oauth2.js"></script>
<script src="options.js"></script>
<style>
h1 { font-size: 20px }
button.authorized { background: green }
Expand All @@ -27,61 +28,14 @@

<body>
<h1>OAuth 2.0 Permissions</h1>
<button id="google" onclick="javascript:authorize('google')">
<button id="google">
Grant Google Access
</button>
<button id="facebook" onclick="javascript:authorize('facebook')">
<button id="facebook" >
Grant Facebook Access
</button>
<button id="github" onclick="javascript:authorize('github')">
<button id="github">
Grant Github Access
</button>
<button id="clear" onclick="javascript:clearAuthorized()">Clear Tokens</button>
<script>
var google = new OAuth2('google', {
client_id: '952993494713-h12m6utvq8g8d8et8n2i68plbrr6cr4d.apps.googleusercontent.com',
client_secret: 'IZ4hBSbosuhoWAX4lyAomm-R',
api_scope: 'https://www.googleapis.com/auth/tasks'
});

var facebook = new OAuth2('facebook', {
client_id: '177955888930840',
client_secret: 'b42a5741bd3d6de6ac591c7b0e279c9f',
api_scope: 'read_stream,user_likes'
});

var github = new OAuth2('github', {
client_id: '09450dfdc3ae76768b08',
client_secret: '8ecfc23e0dba1ce1a295fbabc01fa71db4b80261',
});

function authorize(providerName) {
var provider = window[providerName];
provider.authorize(checkAuthorized);
}

function clearAuthorized() {
console.log('clear');
['google', 'facebook', 'github'].forEach(function(providerName) {
var provider = window[providerName];
provider.clearAccessToken();
});
checkAuthorized();
}

function checkAuthorized() {
console.log('checkAuthorized');
['google', 'facebook', 'github'].forEach(function(providerName) {
var provider = window[providerName];
var button = document.querySelector('#' + providerName);
if (provider.hasAccessToken()) {
button.classList.add('authorized');
} else {
button.classList.remove('authorized');
}
});
}
checkAuthorized();
</script>

<button id="clear">Clear Tokens</button>
</body>
54 changes: 54 additions & 0 deletions samples/mixed/options.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
var google = new OAuth2('google', {
client_id: '952993494713-h12m6utvq8g8d8et8n2i68plbrr6cr4d.apps.googleusercontent.com',
client_secret: 'IZ4hBSbosuhoWAX4lyAomm-R',
api_scope: 'https://www.googleapis.com/auth/tasks'
});

var facebook = new OAuth2('facebook', {
client_id: '177955888930840',
client_secret: 'b42a5741bd3d6de6ac591c7b0e279c9f',
api_scope: 'read_stream,user_likes'
});

var github = new OAuth2('github', {
client_id: '09450dfdc3ae76768b08',
client_secret: '8ecfc23e0dba1ce1a295fbabc01fa71db4b80261',
});

function authorize(providerName) {
var provider = window[providerName];
provider.authorize(checkAuthorized);
}

function clearAuthorized() {
console.log('clear');
['google', 'facebook', 'github'].forEach(function(providerName) {
var provider = window[providerName];
provider.clearAccessToken();
});
checkAuthorized();
}

function checkAuthorized() {
console.log('checkAuthorized');
['google', 'facebook', 'github'].forEach(function(providerName) {
var provider = window[providerName];
var button = document.querySelector('#' + providerName);
if (provider.hasAccessToken()) {
button.classList.add('authorized');
} else {
button.classList.remove('authorized');
}
});
}

document.addEventListener('DOMContentLoaded', function () {
document.querySelector('button#google').addEventListener('click', function() { authorize('google'); });
document.querySelector('button#github').addEventListener('click', function() { authorize('github'); });
document.querySelector('button#facebook').addEventListener('click', function() { authorize('facebook'); });
document.querySelector('button#clear').addEventListener('click', function() { clearAuthorized() });

checkAuthorized();
});


0 comments on commit 31ee7a8

Please sign in to comment.