| 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 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 'message', this.onMessageFromWebview_.bind(this), false); | 138 'message', this.onMessageFromWebview_.bind(this), false); |
| 139 window.addEventListener( | 139 window.addEventListener( |
| 140 'focus', this.onFocus_.bind(this), false); | 140 'focus', this.onFocus_.bind(this), false); |
| 141 window.addEventListener( | 141 window.addEventListener( |
| 142 'popstate', this.onPopState_.bind(this), false); | 142 'popstate', this.onPopState_.bind(this), false); |
| 143 } | 143 } |
| 144 | 144 |
| 145 Authenticator.prototype = Object.create(cr.EventTarget.prototype); | 145 Authenticator.prototype = Object.create(cr.EventTarget.prototype); |
| 146 | 146 |
| 147 /** | 147 /** |
| 148 * Reinitializes authentication parameters so that a failed login attempt |
| 149 * would not result in an infinite loop. |
| 150 */ |
| 151 Authenticator.prototype.clearCredentials_ = function() { |
| 152 this.email_ = null; |
| 153 this.gaiaId_ = null; |
| 154 this.password_ = null; |
| 155 this.oauth_code_ = null; |
| 156 this.chooseWhatToSync_ = false; |
| 157 this.skipForNow_ = false; |
| 158 this.sessionIndex_ = null; |
| 159 this.trusted_ = true; |
| 160 this.authFlow = AuthFlow.DEFAULT; |
| 161 this.samlHandler_.reset(); |
| 162 this.loaded_ = false; |
| 163 }; |
| 164 |
| 165 /** |
| 148 * Loads the authenticator component with the given parameters. | 166 * Loads the authenticator component with the given parameters. |
| 149 * @param {AuthMode} authMode Authorization mode. | 167 * @param {AuthMode} authMode Authorization mode. |
| 150 * @param {Object} data Parameters for the authorization flow. | 168 * @param {Object} data Parameters for the authorization flow. |
| 151 */ | 169 */ |
| 152 Authenticator.prototype.load = function(authMode, data) { | 170 Authenticator.prototype.load = function(authMode, data) { |
| 171 this.clearCredentials_(); |
| 153 this.idpOrigin_ = data.gaiaUrl || IDP_ORIGIN; | 172 this.idpOrigin_ = data.gaiaUrl || IDP_ORIGIN; |
| 154 this.continueUrl_ = data.continueUrl || CONTINUE_URL; | 173 this.continueUrl_ = data.continueUrl || CONTINUE_URL; |
| 155 this.continueUrlWithoutParams_ = | 174 this.continueUrlWithoutParams_ = |
| 156 this.continueUrl_.substring(0, this.continueUrl_.indexOf('?')) || | 175 this.continueUrl_.substring(0, this.continueUrl_.indexOf('?')) || |
| 157 this.continueUrl_; | 176 this.continueUrl_; |
| 158 this.isConstrainedWindow_ = data.constrained == '1'; | 177 this.isConstrainedWindow_ = data.constrained == '1'; |
| 159 this.isMinuteMaidChromeOS = data.isMinuteMaidChromeOS; | 178 this.isMinuteMaidChromeOS = data.isMinuteMaidChromeOS; |
| 160 | 179 |
| 161 this.initialFrameUrl_ = this.constructInitialFrameUrl_(data); | 180 this.initialFrameUrl_ = this.constructInitialFrameUrl_(data); |
| 162 this.reloadUrl_ = data.frameUrl || this.initialFrameUrl_; | 181 this.reloadUrl_ = data.frameUrl || this.initialFrameUrl_; |
| 163 this.authFlow = AuthFlow.DEFAULT; | |
| 164 this.samlHandler_.reset(); | |
| 165 // Don't block insecure content for desktop flow because it lands on | 182 // Don't block insecure content for desktop flow because it lands on |
| 166 // http. Otherwise, block insecure content as long as gaia is https. | 183 // http. Otherwise, block insecure content as long as gaia is https. |
| 167 this.samlHandler_.blockInsecureContent = authMode != AuthMode.DESKTOP && | 184 this.samlHandler_.blockInsecureContent = authMode != AuthMode.DESKTOP && |
| 168 this.idpOrigin_.indexOf('https://') == 0; | 185 this.idpOrigin_.indexOf('https://') == 0; |
| 169 | 186 |
| 170 this.webview_.src = this.reloadUrl_; | 187 this.webview_.src = this.reloadUrl_; |
| 171 | |
| 172 this.loaded_ = false; | |
| 173 }; | 188 }; |
| 174 | 189 |
| 175 /** | 190 /** |
| 176 * Reloads the authenticator component. | 191 * Reloads the authenticator component. |
| 177 */ | 192 */ |
| 178 Authenticator.prototype.reload = function() { | 193 Authenticator.prototype.reload = function() { |
| 194 this.clearCredentials_(); |
| 179 this.webview_.src = this.reloadUrl_; | 195 this.webview_.src = this.reloadUrl_; |
| 180 this.authFlow = AuthFlow.DEFAULT; | |
| 181 this.samlHandler_.reset(); | |
| 182 this.loaded_ = false; | |
| 183 }; | 196 }; |
| 184 | 197 |
| 185 Authenticator.prototype.constructInitialFrameUrl_ = function(data) { | 198 Authenticator.prototype.constructInitialFrameUrl_ = function(data) { |
| 186 var url = this.idpOrigin_ + (data.gaiaPath || IDP_PATH); | 199 var url = this.idpOrigin_ + (data.gaiaPath || IDP_PATH); |
| 187 | 200 |
| 188 if (this.isMinuteMaidChromeOS) { | 201 if (this.isMinuteMaidChromeOS) { |
| 189 if (data.chromeType) | 202 if (data.chromeType) |
| 190 url = appendParam(url, 'chrometype', data.chromeType); | 203 url = appendParam(url, 'chrometype', data.chromeType); |
| 191 if (data.clientId) | 204 if (data.clientId) |
| 192 url = appendParam(url, 'client_id', data.clientId); | 205 url = appendParam(url, 'client_id', data.clientId); |
| (...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 526 Authenticator.AuthFlow = AuthFlow; | 539 Authenticator.AuthFlow = AuthFlow; |
| 527 Authenticator.AuthMode = AuthMode; | 540 Authenticator.AuthMode = AuthMode; |
| 528 Authenticator.SUPPORTED_PARAMS = SUPPORTED_PARAMS; | 541 Authenticator.SUPPORTED_PARAMS = SUPPORTED_PARAMS; |
| 529 | 542 |
| 530 return { | 543 return { |
| 531 // TODO(guohui, xiyuan): Rename GaiaAuthHost to Authenticator once the old | 544 // TODO(guohui, xiyuan): Rename GaiaAuthHost to Authenticator once the old |
| 532 // iframe-based flow is deprecated. | 545 // iframe-based flow is deprecated. |
| 533 GaiaAuthHost: Authenticator | 546 GaiaAuthHost: Authenticator |
| 534 }; | 547 }; |
| 535 }); | 548 }); |
| OLD | NEW |