OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 An UI component to host gaia auth extension in an iframe. | 6 * @fileoverview An UI component to host gaia auth extension in an iframe. |
7 * After the component binds with an iframe, call its {@code load} to start the | 7 * After the component binds with an iframe, call its {@code load} to start the |
8 * authentication flow. There are two events would be raised after this point: | 8 * authentication flow. There are two events would be raised after this point: |
9 * a 'ready' event when the authentication UI is ready to use and a 'completed' | 9 * a 'ready' event when the authentication UI is ready to use and a 'completed' |
10 * event when the authentication is completed successfully. If caller is | 10 * event when the authentication is completed successfully. If caller is |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 * authMode: 'x', // Authorization mode, default/offline/desktop. | 134 * authMode: 'x', // Authorization mode, default/offline/desktop. |
135 * } | 135 * } |
136 * } | 136 * } |
137 * </pre> | 137 * </pre> |
138 * @type {function(Object)} | 138 * @type {function(Object)} |
139 * @private | 139 * @private |
140 */ | 140 */ |
141 successCallback_: null, | 141 successCallback_: null, |
142 | 142 |
143 /** | 143 /** |
144 * Invoked when GAIA indicates login success and SAML was used. At this | |
145 * point, GAIA cookies are present but the identity of the authenticated | |
146 * user is not known. The embedder of GaiaAuthHost should extract the GAIA | |
147 * cookies from the cookie jar, query GAIA for the authenticated user's | |
148 * e-mail address and invoke GaiaAuthHost.setAuthenticatedUserEmail with the | |
149 * result. The argument is an opaque token that should be passed back to | |
150 * GaiaAuthHost.setAuthenticatedUserEmail. | |
151 * @type {function(number)} | |
152 */ | |
153 retrieveAuthenticatedUserEmailCallback_: null, | |
154 | |
155 /** | |
156 * Invoked when the auth flow needs a user to confirm his/her passwords. | 144 * Invoked when the auth flow needs a user to confirm his/her passwords. |
157 * This could happen when there are more than one passwords scraped during | 145 * This could happen when there are more than one passwords scraped during |
158 * SAML flow. The embedder of GaiaAuthHost should show an UI to collect a | 146 * SAML flow. The embedder of GaiaAuthHost should show an UI to collect a |
159 * password from user then call GaiaAuthHost.verifyConfirmedPassword to | 147 * password from user then call GaiaAuthHost.verifyConfirmedPassword to |
160 * verify. If the password is good, the auth flow continues with success | 148 * verify. If the password is good, the auth flow continues with success |
161 * path. Otherwise, confirmPasswordCallback_ is invoked again. | 149 * path. Otherwise, confirmPasswordCallback_ is invoked again. |
162 * @type {function()} | 150 * @type {function()} |
163 */ | 151 */ |
164 confirmPasswordCallback_: null, | 152 confirmPasswordCallback_: null, |
165 | 153 |
166 /** | 154 /** |
167 * Similar to confirmPasswordCallback_ but is used when there is no | 155 * Similar to confirmPasswordCallback_ but is used when there is no |
168 * password scraped after a success authentication. The authenticated user | 156 * password scraped after a success authentication. The authenticated user |
169 * account is passed to the callback. The embedder should take over the | 157 * account is passed to the callback. The embedder should take over the |
170 * flow and decide what to do next. | 158 * flow and decide what to do next. |
171 * @type {function(string)} | 159 * @type {function(string)} |
172 */ | 160 */ |
173 noPasswordCallback_: null, | 161 noPasswordCallback_: null, |
174 | 162 |
175 /** | 163 /** |
176 * Invoked when the authentication flow had to be aborted because content | 164 * Invoked when the authentication flow had to be aborted because content |
177 * served over an unencrypted connection was detected. | 165 * served over an unencrypted connection was detected. |
| 166 */ |
178 insecureContentBlockedCallback_: null, | 167 insecureContentBlockedCallback_: null, |
179 | 168 |
180 /** | 169 /** |
| 170 * Invoked to display an error message to the user when a GAIA error occurs |
| 171 * during authentication. |
| 172 * @type {function()} |
| 173 */ |
| 174 missingGaiaInfoCallback_: null, |
| 175 |
| 176 /** |
| 177 * Invoked to record that the credentials passing API was used. |
| 178 * @type {function()} |
| 179 */ |
| 180 samlApiUsedCallback_: null, |
| 181 |
| 182 /** |
181 * The iframe container. | 183 * The iframe container. |
182 * @type {HTMLIFrameElement} | 184 * @type {HTMLIFrameElement} |
183 */ | 185 */ |
184 get frame() { | 186 get frame() { |
185 return this.frame_; | 187 return this.frame_; |
186 }, | 188 }, |
187 | 189 |
188 /** | 190 /** |
189 * Sets retrieveAuthenticatedUserEmailCallback_. | |
190 * @type {function()} | |
191 */ | |
192 set retrieveAuthenticatedUserEmailCallback(callback) { | |
193 this.retrieveAuthenticatedUserEmailCallback_ = callback; | |
194 }, | |
195 | |
196 /** | |
197 * Sets confirmPasswordCallback_. | 191 * Sets confirmPasswordCallback_. |
198 * @type {function()} | 192 * @type {function()} |
199 */ | 193 */ |
200 set confirmPasswordCallback(callback) { | 194 set confirmPasswordCallback(callback) { |
201 this.confirmPasswordCallback_ = callback; | 195 this.confirmPasswordCallback_ = callback; |
202 }, | 196 }, |
203 | 197 |
204 /** | 198 /** |
205 * Sets noPasswordCallback_. | 199 * Sets noPasswordCallback_. |
206 * @type {function()} | 200 * @type {function()} |
207 */ | 201 */ |
208 set noPasswordCallback(callback) { | 202 set noPasswordCallback(callback) { |
209 this.noPasswordCallback_ = callback; | 203 this.noPasswordCallback_ = callback; |
210 }, | 204 }, |
211 | 205 |
212 /** | 206 /** |
213 * Sets insecureContentBlockedCallback_. | 207 * Sets insecureContentBlockedCallback_. |
214 * @type {function(string)} | 208 * @type {function(string)} |
215 */ | 209 */ |
216 set insecureContentBlockedCallback(callback) { | 210 set insecureContentBlockedCallback(callback) { |
217 this.insecureContentBlockedCallback_ = callback; | 211 this.insecureContentBlockedCallback_ = callback; |
218 }, | 212 }, |
219 | 213 |
220 /** | 214 /** |
| 215 * Sets missingGaiaInfoCallback_. |
| 216 * @type {function()} |
| 217 */ |
| 218 set missingGaiaInfoCallback(callback) { |
| 219 this.missingGaiaInfoCallback_ = callback; |
| 220 }, |
| 221 |
| 222 /** |
| 223 * Sets samlApiUsedCallback_. |
| 224 * @type {function()} |
| 225 */ |
| 226 set samlApiUsedCallback(callback) { |
| 227 this.samlApiUsedCallback_ = callback; |
| 228 }, |
| 229 |
| 230 /** |
221 * Loads the auth extension. | 231 * Loads the auth extension. |
222 * @param {AuthMode} authMode Authorization mode. | 232 * @param {AuthMode} authMode Authorization mode. |
223 * @param {Object} data Parameters for the auth extension. See the auth | 233 * @param {Object} data Parameters for the auth extension. See the auth |
224 * extension's main.js for all supported params and their defaults. | 234 * extension's main.js for all supported params and their defaults. |
225 * @param {function(Object)} successCallback A function to be called when | 235 * @param {function(Object)} successCallback A function to be called when |
226 * the authentication is completed successfully. The callback is | 236 * the authentication is completed successfully. The callback is |
227 * invoked with a credential object. | 237 * invoked with a credential object. |
228 */ | 238 */ |
229 load: function(authMode, data, successCallback) { | 239 load: function(authMode, data, successCallback) { |
230 var params = []; | 240 var params = []; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 */ | 289 */ |
280 verifyConfirmedPassword: function(password) { | 290 verifyConfirmedPassword: function(password) { |
281 var msg = { | 291 var msg = { |
282 method: 'verifyConfirmedPassword', | 292 method: 'verifyConfirmedPassword', |
283 password: password | 293 password: password |
284 }; | 294 }; |
285 this.frame_.contentWindow.postMessage(msg, AUTH_URL_BASE); | 295 this.frame_.contentWindow.postMessage(msg, AUTH_URL_BASE); |
286 }, | 296 }, |
287 | 297 |
288 /** | 298 /** |
289 * Sends the authenticated user's e-mail address to the auth extension. | |
290 * @param {number} attemptToken The opaque token provided to the | |
291 * retrieveAuthenticatedUserEmailCallback_. | |
292 * @param {string} email The authenticated user's e-mail address. | |
293 */ | |
294 setAuthenticatedUserEmail: function(attemptToken, email) { | |
295 var msg = { | |
296 method: 'setAuthenticatedUserEmail', | |
297 attemptToken: attemptToken, | |
298 email: email | |
299 }; | |
300 this.frame_.contentWindow.postMessage(msg, AUTH_URL_BASE); | |
301 }, | |
302 | |
303 /** | |
304 * Invoked to process authentication success. | 299 * Invoked to process authentication success. |
305 * @param {Object} credentials Credential object to pass to success | 300 * @param {Object} credentials Credential object to pass to success |
306 * callback. | 301 * callback. |
307 * @private | 302 * @private |
308 */ | 303 */ |
309 onAuthSuccess_: function(credentials) { | 304 onAuthSuccess_: function(credentials) { |
310 if (this.successCallback_) | 305 if (this.successCallback_) |
311 this.successCallback_(credentials); | 306 this.successCallback_(credentials); |
312 cr.dispatchSimpleEvent(this, 'completed'); | 307 cr.dispatchSimpleEvent(this, 'completed'); |
313 }, | 308 }, |
(...skipping 25 matching lines...) Expand all Loading... |
339 } | 334 } |
340 | 335 |
341 if (/^complete(Login|Authentication)$|^offlineLogin$/.test(msg.method)) { | 336 if (/^complete(Login|Authentication)$|^offlineLogin$/.test(msg.method)) { |
342 if (!msg.email && !this.email_ && !msg.skipForNow) { | 337 if (!msg.email && !this.email_ && !msg.skipForNow) { |
343 var msg = {method: 'redirectToSignin'}; | 338 var msg = {method: 'redirectToSignin'}; |
344 this.frame_.contentWindow.postMessage(msg, AUTH_URL_BASE); | 339 this.frame_.contentWindow.postMessage(msg, AUTH_URL_BASE); |
345 return; | 340 return; |
346 } | 341 } |
347 this.onAuthSuccess_({email: msg.email, | 342 this.onAuthSuccess_({email: msg.email, |
348 password: msg.password, | 343 password: msg.password, |
| 344 gaiaId: msg.gaiaId, |
349 useOffline: msg.method == 'offlineLogin', | 345 useOffline: msg.method == 'offlineLogin', |
350 usingSAML: msg.usingSAML || false, | 346 usingSAML: msg.usingSAML || false, |
351 chooseWhatToSync: msg.chooseWhatToSync, | 347 chooseWhatToSync: msg.chooseWhatToSync, |
352 skipForNow: msg.skipForNow || false, | 348 skipForNow: msg.skipForNow || false, |
353 sessionIndex: msg.sessionIndex || ''}); | 349 sessionIndex: msg.sessionIndex || ''}); |
354 return; | 350 return; |
355 } | 351 } |
356 | 352 |
357 if (msg.method == 'retrieveAuthenticatedUserEmail') { | |
358 if (this.retrieveAuthenticatedUserEmailCallback_) { | |
359 this.retrieveAuthenticatedUserEmailCallback_(msg.attemptToken, | |
360 msg.apiUsed); | |
361 } else { | |
362 console.error( | |
363 'GaiaAuthHost: Invalid retrieveAuthenticatedUserEmailCallback_.'); | |
364 } | |
365 return; | |
366 } | |
367 | |
368 if (msg.method == 'confirmPassword') { | 353 if (msg.method == 'confirmPassword') { |
369 if (this.confirmPasswordCallback_) | 354 if (this.confirmPasswordCallback_) |
370 this.confirmPasswordCallback_(msg.passwordCount); | 355 this.confirmPasswordCallback_(msg.passwordCount); |
371 else | 356 else |
372 console.error('GaiaAuthHost: Invalid confirmPasswordCallback_.'); | 357 console.error('GaiaAuthHost: Invalid confirmPasswordCallback_.'); |
373 return; | 358 return; |
374 } | 359 } |
375 | 360 |
376 if (msg.method == 'noPassword') { | 361 if (msg.method == 'noPassword') { |
377 if (this.noPasswordCallback_) | 362 if (this.noPasswordCallback_) |
(...skipping 17 matching lines...) Expand all Loading... |
395 'GaiaAuthHost: Invalid insecureContentBlockedCallback_.'); | 380 'GaiaAuthHost: Invalid insecureContentBlockedCallback_.'); |
396 } | 381 } |
397 return; | 382 return; |
398 } | 383 } |
399 | 384 |
400 if (msg.method == 'switchToFullTab') { | 385 if (msg.method == 'switchToFullTab') { |
401 chrome.send('switchToFullTab', [msg.url]); | 386 chrome.send('switchToFullTab', [msg.url]); |
402 return; | 387 return; |
403 } | 388 } |
404 | 389 |
| 390 if (msg.method == 'missingGaiaInfo') { |
| 391 if (this.missingGaiaInfoCallback_) { |
| 392 this.missingGaiaInfoCallback_(); |
| 393 } else { |
| 394 console.error('GaiaAuthHost: Invalid missingGaiaInfoCallback_.'); |
| 395 } |
| 396 return; |
| 397 } |
| 398 |
| 399 if (msg.method == 'samlApiUsed') { |
| 400 if (this.samlApiUsedCallback_) { |
| 401 this.samlApiUsedCallback_(); |
| 402 } else { |
| 403 console.error('GaiaAuthHost: Invalid samlApiUsedCallback_.'); |
| 404 } |
| 405 return; |
| 406 } |
| 407 |
405 console.error('Unknown message method=' + msg.method); | 408 console.error('Unknown message method=' + msg.method); |
406 } | 409 } |
407 }; | 410 }; |
408 | 411 |
409 /** | 412 /** |
410 * The current auth flow of the hosted gaia_auth extension. | 413 * The current auth flow of the hosted gaia_auth extension. |
411 * @type {AuthFlow} | 414 * @type {AuthFlow} |
412 */ | 415 */ |
413 cr.defineProperty(GaiaAuthHost, 'authFlow'); | 416 cr.defineProperty(GaiaAuthHost, 'authFlow'); |
414 | 417 |
415 GaiaAuthHost.SUPPORTED_PARAMS = SUPPORTED_PARAMS; | 418 GaiaAuthHost.SUPPORTED_PARAMS = SUPPORTED_PARAMS; |
416 GaiaAuthHost.LOCALIZED_STRING_PARAMS = LOCALIZED_STRING_PARAMS; | 419 GaiaAuthHost.LOCALIZED_STRING_PARAMS = LOCALIZED_STRING_PARAMS; |
417 GaiaAuthHost.AuthMode = AuthMode; | 420 GaiaAuthHost.AuthMode = AuthMode; |
418 GaiaAuthHost.AuthFlow = AuthFlow; | 421 GaiaAuthHost.AuthFlow = AuthFlow; |
419 | 422 |
420 return { | 423 return { |
421 GaiaAuthHost: GaiaAuthHost | 424 GaiaAuthHost: GaiaAuthHost |
422 }; | 425 }; |
423 }); | 426 }); |
OLD | NEW |