| 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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 | 75 |
| 76 /** @return {boolean} True if the app is already authenticated. */ | 76 /** @return {boolean} True if the app is already authenticated. */ |
| 77 remoting.OAuth2.prototype.isAuthenticated = function() { | 77 remoting.OAuth2.prototype.isAuthenticated = function() { |
| 78 if (this.getRefreshToken()) { | 78 if (this.getRefreshToken()) { |
| 79 return true; | 79 return true; |
| 80 } | 80 } |
| 81 return false; | 81 return false; |
| 82 }; | 82 }; |
| 83 | 83 |
| 84 /** | 84 /** |
| 85 * Removes all storage, and effectively unauthenticates the user. | 85 * Remove the cached auth token, if any. |
| 86 * | 86 * |
| 87 * @param {function():void} onDone Completion callback. |
| 87 * @return {void} Nothing. | 88 * @return {void} Nothing. |
| 88 */ | 89 */ |
| 89 remoting.OAuth2.prototype.clear = function() { | 90 remoting.OAuth2.prototype.removeCachedAuthToken = function(onDone) { |
| 90 window.localStorage.removeItem(this.KEY_EMAIL_); | 91 window.localStorage.removeItem(this.KEY_EMAIL_); |
| 91 window.localStorage.removeItem(this.KEY_FULLNAME_); | 92 window.localStorage.removeItem(this.KEY_FULLNAME_); |
| 92 this.clearAccessToken_(); | 93 this.clearAccessToken_(); |
| 93 this.clearRefreshToken_(); | 94 this.clearRefreshToken_(); |
| 95 onDone(); |
| 94 }; | 96 }; |
| 95 | 97 |
| 96 /** | 98 /** |
| 97 * Sets the refresh token. | 99 * Sets the refresh token. |
| 98 * | 100 * |
| 99 * @param {string} token The new refresh token. | 101 * @param {string} token The new refresh token. |
| 100 * @return {void} Nothing. | 102 * @return {void} Nothing. |
| 101 * @private | 103 * @private |
| 102 */ | 104 */ |
| 103 remoting.OAuth2.prototype.setRefreshToken_ = function(token) { | 105 remoting.OAuth2.prototype.setRefreshToken_ = function(token) { |
| (...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 457 * @return {?string} The user's full name, if it has been cached by a previous | 459 * @return {?string} The user's full name, if it has been cached by a previous |
| 458 * call to getUserInfo, otherwise null. | 460 * call to getUserInfo, otherwise null. |
| 459 */ | 461 */ |
| 460 remoting.OAuth2.prototype.getCachedUserFullName = function() { | 462 remoting.OAuth2.prototype.getCachedUserFullName = function() { |
| 461 var value = window.localStorage.getItem(this.KEY_FULLNAME_); | 463 var value = window.localStorage.getItem(this.KEY_FULLNAME_); |
| 462 if (typeof value == 'string') { | 464 if (typeof value == 'string') { |
| 463 return value; | 465 return value; |
| 464 } | 466 } |
| 465 return null; | 467 return null; |
| 466 }; | 468 }; |
| OLD | NEW |