OLD | NEW |
| (Empty) |
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. | |
4 | |
5 /** | |
6 * @fileoverview | |
7 * OAuth2 class that handles retrieval/storage of an OAuth2 token. | |
8 * | |
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. | |
12 */ | |
13 | |
14 'use strict'; | |
15 | |
16 var remoting = remoting || {}; | |
17 | |
18 function retrieveRefreshToken() { | |
19 var query = window.location.search.substring(1); | |
20 var parts = query.split('&'); | |
21 var queryArgs = {}; | |
22 for (var i = 0; i < parts.length; i++) { | |
23 var pair = parts[i].split('='); | |
24 queryArgs[pair[0]] = pair[1]; | |
25 } | |
26 | |
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'], | |
31 function() { | |
32 window.location.replace(chrome.extension.getURL('main.html')); | |
33 }); | |
34 } else { | |
35 window.location.replace(chrome.extension.getURL('main.html')); | |
36 } | |
37 } | |
38 | |
39 window.addEventListener('load', retrieveRefreshToken, false); | |
OLD | NEW |