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 var remoting = remoting || {};
18 function retrieveRefreshToken() {
19 var query = window.location.search.substring(1);
20 var parts = query.split('&');
22 for (var i = 0; i < parts.length; i++) {
23 var pair = parts[i].split('=');
24 queryArgs[pair[0]] = pair[1];
27 if ('code' in queryArgs && 'state' in queryArgs) {
28 remoting.settings = new remoting.Settings();
29 var oauth2 = new remoting.OAuth2();
30 oauth2.exchangeCodeForToken(queryArgs['code'], queryArgs['state'],
32 window.location.replace(chrome.extension.getURL('main.html'));
35 window.location.replace(chrome.extension.getURL('main.html'));
39 window.addEventListener('load', retrieveRefreshToken, false);