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