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 an error occurs | |
171 * during authentication. The function argument is the message to show. | |
172 * @type {function(string)} | |
173 */ | |
174 showFatalAuthErrorCallback_: null, | |
175 | |
176 /** | |
181 * The iframe container. | 177 * The iframe container. |
182 * @type {HTMLIFrameElement} | 178 * @type {HTMLIFrameElement} |
183 */ | 179 */ |
184 get frame() { | 180 get frame() { |
185 return this.frame_; | 181 return this.frame_; |
186 }, | 182 }, |
187 | 183 |
188 /** | 184 /** |
189 * Sets retrieveAuthenticatedUserEmailCallback_. | |
190 * @type {function()} | |
191 */ | |
192 set retrieveAuthenticatedUserEmailCallback(callback) { | |
193 this.retrieveAuthenticatedUserEmailCallback_ = callback; | |
194 }, | |
195 | |
196 /** | |
197 * Sets confirmPasswordCallback_. | 185 * Sets confirmPasswordCallback_. |
198 * @type {function()} | 186 * @type {function()} |
199 */ | 187 */ |
200 set confirmPasswordCallback(callback) { | 188 set confirmPasswordCallback(callback) { |
201 this.confirmPasswordCallback_ = callback; | 189 this.confirmPasswordCallback_ = callback; |
202 }, | 190 }, |
203 | 191 |
204 /** | 192 /** |
205 * Sets noPasswordCallback_. | 193 * Sets noPasswordCallback_. |
206 * @type {function()} | 194 * @type {function()} |
207 */ | 195 */ |
208 set noPasswordCallback(callback) { | 196 set noPasswordCallback(callback) { |
209 this.noPasswordCallback_ = callback; | 197 this.noPasswordCallback_ = callback; |
210 }, | 198 }, |
211 | 199 |
212 /** | 200 /** |
213 * Sets insecureContentBlockedCallback_. | 201 * Sets insecureContentBlockedCallback_. |
214 * @type {function(string)} | 202 * @type {function(string)} |
215 */ | 203 */ |
216 set insecureContentBlockedCallback(callback) { | 204 set insecureContentBlockedCallback(callback) { |
217 this.insecureContentBlockedCallback_ = callback; | 205 this.insecureContentBlockedCallback_ = callback; |
218 }, | 206 }, |
219 | 207 |
220 /** | 208 /** |
209 * Sets showFatalAuthErrorCallback_. | |
210 * @type {function()} | |
211 */ | |
212 set showFatalAuthErrorCallback(callback) { | |
213 this.showFatalAuthErrorCallback_ = callback; | |
214 }, | |
215 | |
216 /** | |
221 * Loads the auth extension. | 217 * Loads the auth extension. |
222 * @param {AuthMode} authMode Authorization mode. | 218 * @param {AuthMode} authMode Authorization mode. |
223 * @param {Object} data Parameters for the auth extension. See the auth | 219 * @param {Object} data Parameters for the auth extension. See the auth |
224 * extension's main.js for all supported params and their defaults. | 220 * extension's main.js for all supported params and their defaults. |
225 * @param {function(Object)} successCallback A function to be called when | 221 * @param {function(Object)} successCallback A function to be called when |
226 * the authentication is completed successfully. The callback is | 222 * the authentication is completed successfully. The callback is |
227 * invoked with a credential object. | 223 * invoked with a credential object. |
228 */ | 224 */ |
229 load: function(authMode, data, successCallback) { | 225 load: function(authMode, data, successCallback) { |
230 var params = []; | 226 var params = []; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
279 */ | 275 */ |
280 verifyConfirmedPassword: function(password) { | 276 verifyConfirmedPassword: function(password) { |
281 var msg = { | 277 var msg = { |
282 method: 'verifyConfirmedPassword', | 278 method: 'verifyConfirmedPassword', |
283 password: password | 279 password: password |
284 }; | 280 }; |
285 this.frame_.contentWindow.postMessage(msg, AUTH_URL_BASE); | 281 this.frame_.contentWindow.postMessage(msg, AUTH_URL_BASE); |
286 }, | 282 }, |
287 | 283 |
288 /** | 284 /** |
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. | 285 * Invoked to process authentication success. |
305 * @param {Object} credentials Credential object to pass to success | 286 * @param {Object} credentials Credential object to pass to success |
306 * callback. | 287 * callback. |
307 * @private | 288 * @private |
308 */ | 289 */ |
309 onAuthSuccess_: function(credentials) { | 290 onAuthSuccess_: function(credentials) { |
310 if (this.successCallback_) | 291 if (this.successCallback_) |
311 this.successCallback_(credentials); | 292 this.successCallback_(credentials); |
312 cr.dispatchSimpleEvent(this, 'completed'); | 293 cr.dispatchSimpleEvent(this, 'completed'); |
313 }, | 294 }, |
(...skipping 25 matching lines...) Expand all Loading... | |
339 } | 320 } |
340 | 321 |
341 if (/^complete(Login|Authentication)$|^offlineLogin$/.test(msg.method)) { | 322 if (/^complete(Login|Authentication)$|^offlineLogin$/.test(msg.method)) { |
342 if (!msg.email && !this.email_ && !msg.skipForNow) { | 323 if (!msg.email && !this.email_ && !msg.skipForNow) { |
343 var msg = {method: 'redirectToSignin'}; | 324 var msg = {method: 'redirectToSignin'}; |
344 this.frame_.contentWindow.postMessage(msg, AUTH_URL_BASE); | 325 this.frame_.contentWindow.postMessage(msg, AUTH_URL_BASE); |
345 return; | 326 return; |
346 } | 327 } |
347 this.onAuthSuccess_({email: msg.email, | 328 this.onAuthSuccess_({email: msg.email, |
348 password: msg.password, | 329 password: msg.password, |
330 gaiaId: msg.gaiaId, | |
349 useOffline: msg.method == 'offlineLogin', | 331 useOffline: msg.method == 'offlineLogin', |
350 usingSAML: msg.usingSAML || false, | 332 usingSAML: msg.usingSAML || false, |
351 chooseWhatToSync: msg.chooseWhatToSync, | 333 chooseWhatToSync: msg.chooseWhatToSync, |
352 skipForNow: msg.skipForNow || false, | 334 skipForNow: msg.skipForNow || false, |
353 sessionIndex: msg.sessionIndex || ''}); | 335 sessionIndex: msg.sessionIndex || ''}); |
354 return; | 336 return; |
355 } | 337 } |
356 | 338 |
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') { | 339 if (msg.method == 'confirmPassword') { |
369 if (this.confirmPasswordCallback_) | 340 if (this.confirmPasswordCallback_) |
370 this.confirmPasswordCallback_(msg.passwordCount); | 341 this.confirmPasswordCallback_(msg.passwordCount); |
371 else | 342 else |
372 console.error('GaiaAuthHost: Invalid confirmPasswordCallback_.'); | 343 console.error('GaiaAuthHost: Invalid confirmPasswordCallback_.'); |
373 return; | 344 return; |
374 } | 345 } |
375 | 346 |
376 if (msg.method == 'noPassword') { | 347 if (msg.method == 'noPassword') { |
377 if (this.noPasswordCallback_) | 348 if (this.noPasswordCallback_) |
(...skipping 17 matching lines...) Expand all Loading... | |
395 'GaiaAuthHost: Invalid insecureContentBlockedCallback_.'); | 366 'GaiaAuthHost: Invalid insecureContentBlockedCallback_.'); |
396 } | 367 } |
397 return; | 368 return; |
398 } | 369 } |
399 | 370 |
400 if (msg.method == 'switchToFullTab') { | 371 if (msg.method == 'switchToFullTab') { |
401 chrome.send('switchToFullTab', [msg.url]); | 372 chrome.send('switchToFullTab', [msg.url]); |
402 return; | 373 return; |
403 } | 374 } |
404 | 375 |
376 if (msg.method == 'showFatalAuthError') { | |
377 this.showFatalAuthErrorCallback_(msg.message); | |
bartfab (slow)
2014/10/17 09:54:56
Instead of a generic |showFatalAuthErrorCallback_|
Roger Tawa OOO till Jul 10th
2014/10/20 16:04:00
Done.
| |
378 return; | |
379 } | |
380 | |
405 console.error('Unknown message method=' + msg.method); | 381 console.error('Unknown message method=' + msg.method); |
406 } | 382 } |
407 }; | 383 }; |
408 | 384 |
409 /** | 385 /** |
410 * The current auth flow of the hosted gaia_auth extension. | 386 * The current auth flow of the hosted gaia_auth extension. |
411 * @type {AuthFlow} | 387 * @type {AuthFlow} |
412 */ | 388 */ |
413 cr.defineProperty(GaiaAuthHost, 'authFlow'); | 389 cr.defineProperty(GaiaAuthHost, 'authFlow'); |
414 | 390 |
415 GaiaAuthHost.SUPPORTED_PARAMS = SUPPORTED_PARAMS; | 391 GaiaAuthHost.SUPPORTED_PARAMS = SUPPORTED_PARAMS; |
416 GaiaAuthHost.LOCALIZED_STRING_PARAMS = LOCALIZED_STRING_PARAMS; | 392 GaiaAuthHost.LOCALIZED_STRING_PARAMS = LOCALIZED_STRING_PARAMS; |
417 GaiaAuthHost.AuthMode = AuthMode; | 393 GaiaAuthHost.AuthMode = AuthMode; |
418 GaiaAuthHost.AuthFlow = AuthFlow; | 394 GaiaAuthHost.AuthFlow = AuthFlow; |
419 | 395 |
420 return { | 396 return { |
421 GaiaAuthHost: GaiaAuthHost | 397 GaiaAuthHost: GaiaAuthHost |
422 }; | 398 }; |
423 }); | 399 }); |
OLD | NEW |