| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <include src="saml_handler.js"> | 5 <include src="saml_handler.js"> |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * @fileoverview An UI component to authenciate to Chrome. The component hosts | 8 * @fileoverview An UI component to authenciate to Chrome. The component hosts |
| 9 * IdP web pages in a webview. A client who is interested in monitoring | 9 * IdP web pages in a webview. A client who is interested in monitoring |
| 10 * authentication events should pass a listener object of type | 10 * authentication events should pass a listener object of type |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 var SIGN_IN_HEADER = 'google-accounts-signin'; | 25 var SIGN_IN_HEADER = 'google-accounts-signin'; |
| 26 var EMBEDDED_FORM_HEADER = 'google-accounts-embedded'; | 26 var EMBEDDED_FORM_HEADER = 'google-accounts-embedded'; |
| 27 var LOCATION_HEADER = 'location'; | 27 var LOCATION_HEADER = 'location'; |
| 28 var COOKIE_HEADER = 'cookie'; | 28 var COOKIE_HEADER = 'cookie'; |
| 29 var SET_COOKIE_HEADER = 'set-cookie'; | 29 var SET_COOKIE_HEADER = 'set-cookie'; |
| 30 var OAUTH_CODE_COOKIE = 'oauth_code'; | 30 var OAUTH_CODE_COOKIE = 'oauth_code'; |
| 31 var GAPS_COOKIE = 'GAPS'; | 31 var GAPS_COOKIE = 'GAPS'; |
| 32 var SERVICE_ID = 'chromeoslogin'; | 32 var SERVICE_ID = 'chromeoslogin'; |
| 33 var EMBEDDED_SETUP_CHROMEOS_ENDPOINT = 'embedded/setup/chromeos'; | 33 var EMBEDDED_SETUP_CHROMEOS_ENDPOINT = 'embedded/setup/chromeos'; |
| 34 var SAML_REDIRECTION_PATH = 'samlredirect'; | 34 var SAML_REDIRECTION_PATH = 'samlredirect'; |
| 35 var BLANK_PAGE_URL = 'about:blank'; | |
| 36 | 35 |
| 37 /** | 36 /** |
| 38 * The source URL parameter for the constrained signin flow. | 37 * The source URL parameter for the constrained signin flow. |
| 39 */ | 38 */ |
| 40 var CONSTRAINED_FLOW_SOURCE = 'chrome'; | 39 var CONSTRAINED_FLOW_SOURCE = 'chrome'; |
| 41 | 40 |
| 42 /** | 41 /** |
| 43 * Enum for the authorization mode, must match AuthMode defined in | 42 * Enum for the authorization mode, must match AuthMode defined in |
| 44 * chrome/browser/ui/webui/inline_login_ui.cc. | 43 * chrome/browser/ui/webui/inline_login_ui.cc. |
| 45 * @enum {number} | 44 * @enum {number} |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 window.addEventListener( | 189 window.addEventListener( |
| 191 'popstate', this.onPopState_.bind(this), false); | 190 'popstate', this.onPopState_.bind(this), false); |
| 192 } | 191 } |
| 193 | 192 |
| 194 Authenticator.prototype = Object.create(cr.EventTarget.prototype); | 193 Authenticator.prototype = Object.create(cr.EventTarget.prototype); |
| 195 | 194 |
| 196 /** | 195 /** |
| 197 * Reinitializes authentication parameters so that a failed login attempt | 196 * Reinitializes authentication parameters so that a failed login attempt |
| 198 * would not result in an infinite loop. | 197 * would not result in an infinite loop. |
| 199 */ | 198 */ |
| 200 Authenticator.prototype.resetStates = function() { | 199 Authenticator.prototype.resetStates_ = function() { |
| 201 this.isLoaded_ = false; | 200 this.isLoaded_ = false; |
| 202 this.email_ = null; | 201 this.email_ = null; |
| 203 this.gaiaId_ = null; | 202 this.gaiaId_ = null; |
| 204 this.password_ = null; | 203 this.password_ = null; |
| 205 this.oauthCode_ = null; | 204 this.oauthCode_ = null; |
| 206 this.gapsCookie_ = null; | 205 this.gapsCookie_ = null; |
| 207 this.gapsCookieSent_ = false; | 206 this.gapsCookieSent_ = false; |
| 208 this.newGapsCookie_ = null; | 207 this.newGapsCookie_ = null; |
| 209 this.readyFired_ = false; | 208 this.readyFired_ = false; |
| 210 this.chooseWhatToSync_ = false; | 209 this.chooseWhatToSync_ = false; |
| 211 this.skipForNow_ = false; | 210 this.skipForNow_ = false; |
| 212 this.sessionIndex_ = null; | 211 this.sessionIndex_ = null; |
| 213 this.trusted_ = true; | 212 this.trusted_ = true; |
| 214 this.authFlow = AuthFlow.DEFAULT; | 213 this.authFlow = AuthFlow.DEFAULT; |
| 215 this.samlHandler_.reset(); | 214 this.samlHandler_.reset(); |
| 216 this.videoEnabled = false; | 215 this.videoEnabled = false; |
| 217 }; | 216 }; |
| 218 | 217 |
| 219 /** | 218 /** |
| 220 * Resets the webview to the blank page. | |
| 221 */ | |
| 222 Authenticator.prototype.resetWebview = function() { | |
| 223 this.webview_.src = BLANK_PAGE_URL; | |
| 224 }; | |
| 225 | |
| 226 /** | |
| 227 * Loads the authenticator component with the given parameters. | 219 * Loads the authenticator component with the given parameters. |
| 228 * @param {AuthMode} authMode Authorization mode. | 220 * @param {AuthMode} authMode Authorization mode. |
| 229 * @param {Object} data Parameters for the authorization flow. | 221 * @param {Object} data Parameters for the authorization flow. |
| 230 */ | 222 */ |
| 231 Authenticator.prototype.load = function(authMode, data) { | 223 Authenticator.prototype.load = function(authMode, data) { |
| 232 this.authMode = authMode; | 224 this.authMode = authMode; |
| 233 this.resetStates(); | 225 this.resetStates_(); |
| 234 // gaiaUrl parameter is used for testing. Once defined, it is never changed. | 226 // gaiaUrl parameter is used for testing. Once defined, it is never changed. |
| 235 this.idpOrigin_ = data.gaiaUrl || IDP_ORIGIN; | 227 this.idpOrigin_ = data.gaiaUrl || IDP_ORIGIN; |
| 236 this.continueUrl_ = data.continueUrl || CONTINUE_URL; | 228 this.continueUrl_ = data.continueUrl || CONTINUE_URL; |
| 237 this.continueUrlWithoutParams_ = | 229 this.continueUrlWithoutParams_ = |
| 238 this.continueUrl_.substring(0, this.continueUrl_.indexOf('?')) || | 230 this.continueUrl_.substring(0, this.continueUrl_.indexOf('?')) || |
| 239 this.continueUrl_; | 231 this.continueUrl_; |
| 240 this.isConstrainedWindow_ = data.constrained == '1'; | 232 this.isConstrainedWindow_ = data.constrained == '1'; |
| 241 this.isNewGaiaFlow = data.isNewGaiaFlow; | 233 this.isNewGaiaFlow = data.isNewGaiaFlow; |
| 242 this.useEafe_ = data.useEafe || false; | 234 this.useEafe_ = data.useEafe || false; |
| 243 this.clientId_ = data.clientId; | 235 this.clientId_ = data.clientId; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 271 } | 263 } |
| 272 | 264 |
| 273 this.webview_.src = this.reloadUrl_; | 265 this.webview_.src = this.reloadUrl_; |
| 274 this.isLoaded_ = true; | 266 this.isLoaded_ = true; |
| 275 }; | 267 }; |
| 276 | 268 |
| 277 /** | 269 /** |
| 278 * Reloads the authenticator component. | 270 * Reloads the authenticator component. |
| 279 */ | 271 */ |
| 280 Authenticator.prototype.reload = function() { | 272 Authenticator.prototype.reload = function() { |
| 281 this.resetStates(); | 273 this.resetStates_(); |
| 282 this.webview_.src = this.reloadUrl_; | 274 this.webview_.src = this.reloadUrl_; |
| 283 this.isLoaded_ = true; | 275 this.isLoaded_ = true; |
| 284 }; | 276 }; |
| 285 | 277 |
| 286 Authenticator.prototype.constructInitialFrameUrl_ = function(data) { | 278 Authenticator.prototype.constructInitialFrameUrl_ = function(data) { |
| 287 if (data.doSamlRedirect) { | 279 if (data.doSamlRedirect) { |
| 288 var url = this.idpOrigin_ + SAML_REDIRECTION_PATH; | 280 var url = this.idpOrigin_ + SAML_REDIRECTION_PATH; |
| 289 url = appendParam(url, 'domain', data.enterpriseDomain); | 281 url = appendParam(url, 'domain', data.enterpriseDomain); |
| 290 url = appendParam(url, 'continue', data.gaiaUrl + | 282 url = appendParam(url, 'continue', data.gaiaUrl + |
| 291 'o/oauth2/programmatic_auth?hl=' + data.hl + | 283 'o/oauth2/programmatic_auth?hl=' + data.hl + |
| (...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 704 password: this.password_ || '', | 696 password: this.password_ || '', |
| 705 authCode: this.oauthCode_, | 697 authCode: this.oauthCode_, |
| 706 usingSAML: this.authFlow == AuthFlow.SAML, | 698 usingSAML: this.authFlow == AuthFlow.SAML, |
| 707 chooseWhatToSync: this.chooseWhatToSync_, | 699 chooseWhatToSync: this.chooseWhatToSync_, |
| 708 skipForNow: this.skipForNow_, | 700 skipForNow: this.skipForNow_, |
| 709 sessionIndex: this.sessionIndex_ || '', | 701 sessionIndex: this.sessionIndex_ || '', |
| 710 trusted: this.trusted_, | 702 trusted: this.trusted_, |
| 711 gapsCookie: this.newGapsCookie_ || this.gapsCookie_ || '', | 703 gapsCookie: this.newGapsCookie_ || this.gapsCookie_ || '', |
| 712 } | 704 } |
| 713 })); | 705 })); |
| 714 this.resetStates(); | 706 this.resetStates_(); |
| 715 }; | 707 }; |
| 716 | 708 |
| 717 /** | 709 /** |
| 718 * Invoked when |samlHandler_| fires 'insecureContentBlocked' event. | 710 * Invoked when |samlHandler_| fires 'insecureContentBlocked' event. |
| 719 * @private | 711 * @private |
| 720 */ | 712 */ |
| 721 Authenticator.prototype.onInsecureContentBlocked_ = function(e) { | 713 Authenticator.prototype.onInsecureContentBlocked_ = function(e) { |
| 722 if (!this.isLoaded_) | 714 if (!this.isLoaded_) |
| 723 return; | 715 return; |
| 724 | 716 |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 787 if (currentUrl.lastIndexOf(this.idpOrigin_) == 0) { | 779 if (currentUrl.lastIndexOf(this.idpOrigin_) == 0) { |
| 788 var msg = { | 780 var msg = { |
| 789 'method': 'handshake', | 781 'method': 'handshake', |
| 790 }; | 782 }; |
| 791 | 783 |
| 792 this.webview_.contentWindow.postMessage(msg, currentUrl); | 784 this.webview_.contentWindow.postMessage(msg, currentUrl); |
| 793 | 785 |
| 794 this.fireReadyEvent_(); | 786 this.fireReadyEvent_(); |
| 795 // Focus webview after dispatching event when webview is already visible. | 787 // Focus webview after dispatching event when webview is already visible. |
| 796 this.webview_.focus(); | 788 this.webview_.focus(); |
| 797 } else if (currentUrl == BLANK_PAGE_URL) { | |
| 798 this.fireReadyEvent_(); | |
| 799 } | 789 } |
| 800 }; | 790 }; |
| 801 | 791 |
| 802 /** | 792 /** |
| 803 * Invoked when the webview fails loading a page. | 793 * Invoked when the webview fails loading a page. |
| 804 * @private | 794 * @private |
| 805 */ | 795 */ |
| 806 Authenticator.prototype.onLoadAbort_ = function(e) { | 796 Authenticator.prototype.onLoadAbort_ = function(e) { |
| 807 this.dispatchEvent(new CustomEvent('loadAbort', | 797 this.dispatchEvent(new CustomEvent('loadAbort', |
| 808 {detail: {error: e.reason, | 798 {detail: {error: e.reason, |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 873 Authenticator.AuthMode = AuthMode; | 863 Authenticator.AuthMode = AuthMode; |
| 874 Authenticator.SUPPORTED_PARAMS = SUPPORTED_PARAMS; | 864 Authenticator.SUPPORTED_PARAMS = SUPPORTED_PARAMS; |
| 875 | 865 |
| 876 return { | 866 return { |
| 877 // TODO(guohui, xiyuan): Rename GaiaAuthHost to Authenticator once the old | 867 // TODO(guohui, xiyuan): Rename GaiaAuthHost to Authenticator once the old |
| 878 // iframe-based flow is deprecated. | 868 // iframe-based flow is deprecated. |
| 879 GaiaAuthHost: Authenticator, | 869 GaiaAuthHost: Authenticator, |
| 880 Authenticator: Authenticator | 870 Authenticator: Authenticator |
| 881 }; | 871 }; |
| 882 }); | 872 }); |
| OLD | NEW |