1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
7 * OAuth2 class that handles retrieval/storage of an OAuth2 token.
9 * Uses a content script to trampoline the OAuth redirect page back into the
10 * extension context. This works around the lack of native support for
11 * chrome-extensions in OAuth2.
16 function retrieveRefreshToken() {
17 var query
= window
.location
.search
.substring(1);
18 var parts
= query
.split('&');
20 for (var i
= 0; i
< parts
.length
; i
++) {
21 var pair
= parts
[i
].split('=');
22 queryArgs
[pair
[0]] = pair
[1];
24 if ('code' in queryArgs
) {
25 var oauth2
= new remoting
.OAuth2();
26 oauth2
.exchangeCodeForToken(queryArgs
['code'], function() {
27 window
.location
.replace(chrome
.extension
.getURL('main.html'));
30 window
.location
.replace(chrome
.extension
.getURL('main.html'));
34 window
.addEventListener('load', retrieveRefreshToken
, false);