OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 /** | 5 /** |
6 * @fileoverview | 6 * @fileoverview |
7 * OAuth2 class that handles retrieval/storage of an OAuth2 token. | 7 * OAuth2 class that handles retrieval/storage of an OAuth2 token. |
8 * | 8 * |
9 * Uses a content script to trampoline the OAuth redirect page back into the | 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 | 10 * extension context. This works around the lack of native support for |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 // we return will be valid for at least 2 minutes. | 219 // we return will be valid for at least 2 minutes. |
220 // If the access token is to be useful, this object must make some | 220 // If the access token is to be useful, this object must make some |
221 // guarantee as to how long the token will be valid for. | 221 // guarantee as to how long the token will be valid for. |
222 // The choice of 2 minutes is arbitrary, but that length of time | 222 // The choice of 2 minutes is arbitrary, but that length of time |
223 // is part of the contract satisfied by callWithToken(). | 223 // is part of the contract satisfied by callWithToken(). |
224 // Offset by a further 30 seconds to account for RTT issues. | 224 // Offset by a further 30 seconds to account for RTT issues. |
225 this.setAccessToken(tokens['access_token'], | 225 this.setAccessToken(tokens['access_token'], |
226 (tokens['expires_in'] - (120 + 30)) * 1000 + Date.now()); | 226 (tokens['expires_in'] - (120 + 30)) * 1000 + Date.now()); |
227 } catch (err) { | 227 } catch (err) { |
228 console.error('Invalid "token" response from server:', | 228 console.error('Invalid "token" response from server:', |
229 /** @type {*} */ err); | 229 /** @type {*} */ (err)); |
230 } | 230 } |
231 } else { | 231 } else { |
232 console.error('Failed to get tokens. Status: ' + xhr.status + | 232 console.error('Failed to get tokens. Status: ' + xhr.status + |
233 ' response: ' + xhr.responseText); | 233 ' response: ' + xhr.responseText); |
234 } | 234 } |
235 }; | 235 }; |
236 | 236 |
237 /** | 237 /** |
238 * Asynchronously retrieves a new access token from the server. | 238 * Asynchronously retrieves a new access token from the server. |
239 * | 239 * |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
409 * @return {?string} The email address, if it has been cached by a previous call | 409 * @return {?string} The email address, if it has been cached by a previous call |
410 * to getEmail, otherwise null. | 410 * to getEmail, otherwise null. |
411 */ | 411 */ |
412 remoting.OAuth2.prototype.getCachedEmail = function() { | 412 remoting.OAuth2.prototype.getCachedEmail = function() { |
413 var value = window.localStorage.getItem(this.KEY_EMAIL_); | 413 var value = window.localStorage.getItem(this.KEY_EMAIL_); |
414 if (typeof value == 'string') { | 414 if (typeof value == 'string') { |
415 return value; | 415 return value; |
416 } | 416 } |
417 return null; | 417 return null; |
418 }; | 418 }; |
OLD | NEW |