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 * Authenticator class wraps the communications between Gaia and its host. | 6 * Authenticator class wraps the communications between Gaia and its host. |
7 */ | 7 */ |
8 function Authenticator() { | 8 function Authenticator() { |
9 } | 9 } |
10 | 10 |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 /** | 194 /** |
195 * Invoked when 'enableSAML' event is received to initialize SAML support. | 195 * Invoked when 'enableSAML' event is received to initialize SAML support. |
196 */ | 196 */ |
197 onEnableSAML_: function() { | 197 onEnableSAML_: function() { |
198 this.isSAMLFlow_ = false; | 198 this.isSAMLFlow_ = false; |
199 | 199 |
200 this.samlSupportChannel_ = new Channel(); | 200 this.samlSupportChannel_ = new Channel(); |
201 this.samlSupportChannel_.connect('authMain'); | 201 this.samlSupportChannel_.connect('authMain'); |
202 this.samlSupportChannel_.registerMessage( | 202 this.samlSupportChannel_.registerMessage( |
203 'onAuthPageLoaded', this.onAuthPageLoaded_.bind(this)); | 203 'onAuthPageLoaded', this.onAuthPageLoaded_.bind(this)); |
| 204 this.samlSupportChannel_.registerMessage( |
| 205 'apiCall', this.onAPICall_.bind(this)); |
204 this.samlSupportChannel_.send({ | 206 this.samlSupportChannel_.send({ |
205 name: 'setGaiaUrl', | 207 name: 'setGaiaUrl', |
206 gaiaUrl: this.gaiaUrl_ | 208 gaiaUrl: this.gaiaUrl_ |
207 }); | 209 }); |
208 }, | 210 }, |
209 | 211 |
210 /** | 212 /** |
211 * Invoked when the background page sends 'onHostedPageLoaded' message. | 213 * Invoked when the background page sends 'onHostedPageLoaded' message. |
212 * @param {!Object} msg Details sent with the message. | 214 * @param {!Object} msg Details sent with the message. |
213 */ | 215 */ |
214 onAuthPageLoaded_: function(msg) { | 216 onAuthPageLoaded_: function(msg) { |
215 var isSAMLPage = msg.url.indexOf(this.gaiaUrl_) != 0; | 217 var isSAMLPage = msg.url.indexOf(this.gaiaUrl_) != 0; |
216 | 218 |
217 if (isSAMLPage && !this.isSAMLFlow_) { | 219 if (isSAMLPage && !this.isSAMLFlow_) { |
218 // GAIA redirected to a SAML login page. The credentials provided to this | 220 // GAIA redirected to a SAML login page. The credentials provided to this |
219 // page will determine what user gets logged in. The credentials obtained | 221 // page will determine what user gets logged in. The credentials obtained |
220 // from the GAIA login from are no longer relevant and can be discarded. | 222 // from the GAIA login from are no longer relevant and can be discarded. |
221 this.isSAMLFlow_ = true; | 223 this.isSAMLFlow_ = true; |
222 this.email_ = null; | 224 this.email_ = null; |
223 this.password_ = null; | 225 this.password_ = null; |
224 } | 226 } |
225 | 227 |
226 window.parent.postMessage({ | 228 window.parent.postMessage({ |
227 'method': 'authPageLoaded', | 229 'method': 'authPageLoaded', |
228 'isSAML': this.isSAMLFlow_, | 230 'isSAML': this.isSAMLFlow_, |
229 'domain': extractDomain(msg.url) | 231 'domain': extractDomain(msg.url) |
230 }, this.parentPage_); | 232 }, this.parentPage_); |
231 }, | 233 }, |
232 | 234 |
| 235 /** |
| 236 * Invoked when one of the credential passing API methods is called by a SAML |
| 237 * provider. |
| 238 * @param {!Object} msg Details of the API call. |
| 239 */ |
| 240 onAPICall_: function(msg) { |
| 241 var call = msg.call; |
| 242 if (call.method == 'add') { |
| 243 this.apiToken_ = call.token; |
| 244 this.email_ = call.user; |
| 245 this.password_ = call.password; |
| 246 } else if (call.method == 'confirm') { |
| 247 if (call.token != this.apiToken_) |
| 248 console.error('Authenticator.onAPICall_: token mismatch'); |
| 249 } else { |
| 250 console.error('Authenticator.onAPICall_: unknown message'); |
| 251 } |
| 252 }, |
| 253 |
233 onLoginUILoaded: function() { | 254 onLoginUILoaded: function() { |
234 var msg = { | 255 var msg = { |
235 'method': 'loginUILoaded' | 256 'method': 'loginUILoaded' |
236 }; | 257 }; |
237 window.parent.postMessage(msg, this.parentPage_); | 258 window.parent.postMessage(msg, this.parentPage_); |
238 if (this.inlineMode_) { | 259 if (this.inlineMode_) { |
239 // TODO(guohui): temporary workaround until webview team fixes the focus | 260 // TODO(guohui): temporary workaround until webview team fixes the focus |
240 // on their side. | 261 // on their side. |
241 var gaiaFrame = $('gaia-frame'); | 262 var gaiaFrame = $('gaia-frame'); |
242 gaiaFrame.focus(); | 263 gaiaFrame.focus(); |
243 gaiaFrame.onblur = function() { | 264 gaiaFrame.onblur = function() { |
244 gaiaFrame.focus(); | 265 gaiaFrame.focus(); |
245 }; | 266 }; |
246 } | 267 } |
247 this.loaded_ = true; | 268 this.loaded_ = true; |
248 }, | 269 }, |
249 | 270 |
250 onConfirmLogin_: function() { | 271 onConfirmLogin_: function() { |
251 if (!this.isSAMLFlow_) { | 272 if (!this.isSAMLFlow_) { |
252 this.completeLogin(this.email_, this.password_); | 273 this.completeLogin(this.email_, this.password_); |
253 return; | 274 return; |
254 } | 275 } |
255 | 276 |
256 // Retrieve the e-mail address of the user who just authenticated from GAIA. | 277 // Retrieve the e-mail address of the user who just authenticated from GAIA. |
257 window.parent.postMessage({method: 'retrieveAuthenticatedUserEmail', | 278 window.parent.postMessage({method: 'retrieveAuthenticatedUserEmail', |
258 attemptToken: this.attemptToken_}, | 279 attemptToken: this.attemptToken_}, |
259 this.parentPage_); | 280 this.parentPage_); |
260 | 281 |
261 this.samlSupportChannel_.sendWithCallback( | 282 if (!this.password_) { |
262 {name: 'getScrapedPasswords'}, | 283 this.samlSupportChannel_.sendWithCallback( |
263 function(passwords) { | 284 {name: 'getScrapedPasswords'}, |
264 if (passwords.length == 0) { | 285 function(passwords) { |
265 window.parent.postMessage( | 286 if (passwords.length == 0) { |
266 {method: 'noPassword', email: this.email_}, | 287 window.parent.postMessage( |
267 this.parentPage_); | 288 {method: 'noPassword', email: this.email_}, |
268 } else { | 289 this.parentPage_); |
269 window.parent.postMessage( | 290 } else { |
270 {method: 'confirmPassword', email: this.email_}, | 291 window.parent.postMessage( |
271 this.parentPage_); | 292 {method: 'confirmPassword', email: this.email_}, |
272 } | 293 this.parentPage_); |
273 }.bind(this)); | 294 } |
| 295 }.bind(this)); |
| 296 } |
274 }, | 297 }, |
275 | 298 |
276 maybeCompleteSAMLLogin_: function() { | 299 maybeCompleteSAMLLogin_: function() { |
277 // SAML login is complete when the user's e-mail address has been retrieved | 300 // SAML login is complete when the user's e-mail address has been retrieved |
278 // from GAIA and the user has successfully confirmed the password. | 301 // from GAIA and the user has successfully confirmed the password. |
279 if (this.email_ !== null && this.password_ !== null) | 302 if (this.email_ !== null && this.password_ !== null) |
280 this.completeLogin(this.email_, this.password_); | 303 this.completeLogin(this.email_, this.password_); |
281 }, | 304 }, |
282 | 305 |
283 onVerifyConfirmedPassword_: function(password) { | 306 onVerifyConfirmedPassword_: function(password) { |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
334 } else if (msg.method == 'redirectToSignin' && | 357 } else if (msg.method == 'redirectToSignin' && |
335 this.isParentMessage_(e)) { | 358 this.isParentMessage_(e)) { |
336 $('gaia-frame').src = this.constructInitialFrameUrl_(); | 359 $('gaia-frame').src = this.constructInitialFrameUrl_(); |
337 } else { | 360 } else { |
338 console.error('Authenticator.onMessage: unknown message + origin!?'); | 361 console.error('Authenticator.onMessage: unknown message + origin!?'); |
339 } | 362 } |
340 } | 363 } |
341 }; | 364 }; |
342 | 365 |
343 Authenticator.getInstance().initialize(); | 366 Authenticator.getInstance().initialize(); |
OLD | NEW |