| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 * Redirect page to get a new OAuth2 Refresh Token. | 229 * Redirect page to get a new OAuth2 Refresh Token. |
| 230 * | 230 * |
| 231 * @return {void} Nothing. | 231 * @return {void} Nothing. |
| 232 */ | 232 */ |
| 233 remoting.OAuth2.prototype.doAuthRedirect = function() { | 233 remoting.OAuth2.prototype.doAuthRedirect = function() { |
| 234 var GET_CODE_URL = 'https://accounts.google.com/o/oauth2/auth?' + | 234 var GET_CODE_URL = 'https://accounts.google.com/o/oauth2/auth?' + |
| 235 remoting.xhr.urlencodeParamHash({ | 235 remoting.xhr.urlencodeParamHash({ |
| 236 'client_id': this.CLIENT_ID_, | 236 'client_id': this.CLIENT_ID_, |
| 237 'redirect_uri': this.REDIRECT_URI_, | 237 'redirect_uri': this.REDIRECT_URI_, |
| 238 'scope': this.SCOPE_, | 238 'scope': this.SCOPE_, |
| 239 'response_type': 'code' | 239 'response_type': 'code', |
| 240 'access_type': 'offline', |
| 241 'approval_prompt': 'force' |
| 240 }); | 242 }); |
| 241 window.location.replace(GET_CODE_URL); | 243 window.location.replace(GET_CODE_URL); |
| 242 }; | 244 }; |
| 243 | 245 |
| 244 /** | 246 /** |
| 245 * Asynchronously exchanges an authorization code for a refresh token. | 247 * Asynchronously exchanges an authorization code for a refresh token. |
| 246 * | 248 * |
| 247 * @param {string} code The new refresh token. | 249 * @param {string} code The new refresh token. |
| 248 * @param {function(XMLHttpRequest):void} onDone Callback to invoke on | 250 * @param {function(XMLHttpRequest):void} onDone Callback to invoke on |
| 249 * completion. | 251 * completion. |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 337 * @return {?string} The email address, if it has been cached by a previous call | 339 * @return {?string} The email address, if it has been cached by a previous call |
| 338 * to getEmail, otherwise null. | 340 * to getEmail, otherwise null. |
| 339 */ | 341 */ |
| 340 remoting.OAuth2.prototype.getCachedEmail = function() { | 342 remoting.OAuth2.prototype.getCachedEmail = function() { |
| 341 var value = window.localStorage.getItem(this.KEY_EMAIL_); | 343 var value = window.localStorage.getItem(this.KEY_EMAIL_); |
| 342 if (typeof value == 'string') { | 344 if (typeof value == 'string') { |
| 343 return value; | 345 return value; |
| 344 } | 346 } |
| 345 return null; | 347 return null; |
| 346 }; | 348 }; |
| OLD | NEW |