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=} opt_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(opt_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 if (opt_onDone) { |
| 96 opt_onDone(); |
| 97 } |
94 }; | 98 }; |
95 | 99 |
96 /** | 100 /** |
97 * Sets the refresh token. | 101 * Sets the refresh token. |
98 * | 102 * |
99 * @param {string} token The new refresh token. | 103 * @param {string} token The new refresh token. |
100 * @return {void} Nothing. | 104 * @return {void} Nothing. |
101 * @private | 105 * @private |
102 */ | 106 */ |
103 remoting.OAuth2.prototype.setRefreshToken_ = function(token) { | 107 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 | 461 * @return {?string} The user's full name, if it has been cached by a previous |
458 * call to getUserInfo, otherwise null. | 462 * call to getUserInfo, otherwise null. |
459 */ | 463 */ |
460 remoting.OAuth2.prototype.getCachedUserFullName = function() { | 464 remoting.OAuth2.prototype.getCachedUserFullName = function() { |
461 var value = window.localStorage.getItem(this.KEY_FULLNAME_); | 465 var value = window.localStorage.getItem(this.KEY_FULLNAME_); |
462 if (typeof value == 'string') { | 466 if (typeof value == 'string') { |
463 return value; | 467 return value; |
464 } | 468 } |
465 return null; | 469 return null; |
466 }; | 470 }; |
OLD | NEW |