| 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 * Wrapper class for Chrome's identity API. | 7 * Wrapper class for Chrome's identity API. |
| 8 */ | 8 */ |
| 9 | 9 |
| 10 'use strict'; | 10 'use strict'; |
| 11 | 11 |
| 12 /** @suppress {duplicate} */ | 12 /** @suppress {duplicate} */ |
| 13 var remoting = remoting || {}; | 13 var remoting = remoting || {}; |
| 14 | 14 |
| 15 /** | 15 /** |
| 16 * TODO(jamiewalch): Remove remoting.OAuth2 from this type annotation when | |
| 17 * the Apps v2 work is complete. | |
| 18 * | |
| 19 * @type {remoting.Identity} | 16 * @type {remoting.Identity} |
| 20 */ | 17 */ |
| 21 remoting.identity = null; | 18 remoting.identity = null; |
| 22 | 19 |
| 23 /** | 20 /** |
| 24 * @param {remoting.Identity.ConsentDialog=} opt_consentDialog | 21 * @param {remoting.Identity.ConsentDialog=} opt_consentDialog |
| 25 * @constructor | 22 * @constructor |
| 26 */ | 23 */ |
| 27 remoting.Identity = function(opt_consentDialog) { | 24 remoting.Identity = function(opt_consentDialog) { |
| 28 /** @private */ | 25 /** @private */ |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 * @return {!Promise<string>} Promise resolved with the user's email | 153 * @return {!Promise<string>} Promise resolved with the user's email |
| 157 * address or rejected with a remoting.Error. | 154 * address or rejected with a remoting.Error. |
| 158 */ | 155 */ |
| 159 remoting.Identity.prototype.getEmail = function() { | 156 remoting.Identity.prototype.getEmail = function() { |
| 160 return this.getUserInfo().then(function(userInfo) { | 157 return this.getUserInfo().then(function(userInfo) { |
| 161 return userInfo.email; | 158 return userInfo.email; |
| 162 }); | 159 }); |
| 163 }; | 160 }; |
| 164 | 161 |
| 165 /** | 162 /** |
| 166 * Gets the user's email address, or null if no successful call to | |
| 167 * getUserInfo has been made. | |
| 168 * | |
| 169 * @return {?string} The cached email address, if available. | |
| 170 */ | |
| 171 remoting.Identity.prototype.getCachedEmail = function() { | |
| 172 return this.email_; | |
| 173 }; | |
| 174 | |
| 175 /** | |
| 176 * Gets the user's full name. | |
| 177 * | |
| 178 * This will return null if either: | |
| 179 * No successful call to getUserInfo has been made, or | |
| 180 * The webapp doesn't have permission to access this value. | |
| 181 * | |
| 182 * @return {?string} The cached user's full name, if available. | |
| 183 */ | |
| 184 remoting.Identity.prototype.getCachedUserFullName = function() { | |
| 185 return this.fullName_; | |
| 186 }; | |
| 187 | |
| 188 /** | |
| 189 * Callback for the getAuthToken API. | 163 * Callback for the getAuthToken API. |
| 190 * | 164 * |
| 191 * @param {boolean} interactive The value of the "interactive" parameter to | 165 * @param {boolean} interactive The value of the "interactive" parameter to |
| 192 * getAuthToken. | 166 * getAuthToken. |
| 193 * @param {?string} token The auth token, or null if the request failed. | 167 * @param {?string} token The auth token, or null if the request failed. |
| 194 * @private | 168 * @private |
| 195 */ | 169 */ |
| 196 remoting.Identity.prototype.onAuthComplete_ = function(interactive, token) { | 170 remoting.Identity.prototype.onAuthComplete_ = function(interactive, token) { |
| 197 var authTokenDeferred = this.authTokenDeferred_; | 171 var authTokenDeferred = this.authTokenDeferred_; |
| 198 | 172 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 227 }; | 201 }; |
| 228 | 202 |
| 229 /** | 203 /** |
| 230 * Returns whether the web app has authenticated with the Google services. | 204 * Returns whether the web app has authenticated with the Google services. |
| 231 * | 205 * |
| 232 * @return {boolean} | 206 * @return {boolean} |
| 233 */ | 207 */ |
| 234 remoting.Identity.prototype.isAuthenticated = function() { | 208 remoting.Identity.prototype.isAuthenticated = function() { |
| 235 return remoting.identity.email_ !== ''; | 209 return remoting.identity.email_ !== ''; |
| 236 }; | 210 }; |
| OLD | NEW |