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 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 * authMode: 'x', // Authorization mode, default/inline/offline. | 143 * authMode: 'x', // Authorization mode, default/inline/offline. |
144 * } | 144 * } |
145 * } | 145 * } |
146 * </pre> | 146 * </pre> |
147 * @type {function(Object)} | 147 * @type {function(Object)} |
148 * @private | 148 * @private |
149 */ | 149 */ |
150 successCallback_: null, | 150 successCallback_: null, |
151 | 151 |
152 /** | 152 /** |
| 153 * Invoked when GAIA indicates login success and SAML was used. At this |
| 154 * point, GAIA cookies are present but the identity of the authenticated |
| 155 * user is not known. The embedder of GaiaAuthHost should extract the GAIA |
| 156 * cookies from the cookie jar, query GAIA for the authenticated user's |
| 157 * e-mail address and invoke GaiaAuthHost.setAuthenticatedUserEmail with the |
| 158 * result. The argument is an opaque token that should be passed back to |
| 159 * GaiaAuthHost.setAuthenticatedUserEmail. |
| 160 * @type {function(number)} |
| 161 */ |
| 162 retrieveAuthenticatedUserEmailCallback_: null, |
| 163 |
| 164 /** |
153 * Invoked when the auth flow needs a user to confirm his/her passwords. | 165 * Invoked when the auth flow needs a user to confirm his/her passwords. |
154 * This could happen when there are more than one passwords scraped during | 166 * This could happen when there are more than one passwords scraped during |
155 * SAML flow. The embedder of GaiaAuthHost should show an UI to collect a | 167 * SAML flow. The embedder of GaiaAuthHost should show an UI to collect a |
156 * password from user then call GaiaAuthHost.verifyConfirmedPassword to | 168 * password from user then call GaiaAuthHost.verifyConfirmedPassword to |
157 * verify. If the password is good, the auth flow continues with success | 169 * verify. If the password is good, the auth flow continues with success |
158 * path. Otherwise, confirmPasswordCallback_ is invoked again. | 170 * path. Otherwise, confirmPasswordCallback_ is invoked again. |
159 * @type {function()} | 171 * @type {function()} |
160 */ | 172 */ |
161 confirmPasswordCallback_: null, | 173 confirmPasswordCallback_: null, |
162 | 174 |
163 /** | 175 /** |
164 * Similar to confirmPasswordCallback_ but is used when there is no | 176 * Similar to confirmPasswordCallback_ but is used when there is no |
165 * password scraped after a success authentication. The authenticated user | 177 * password scraped after a success authentication. The authenticated user |
166 * account is passed to the callback. The embedder should take over the | 178 * account is passed to the callback. The embedder should take over the |
167 * flow and decide what to do next. | 179 * flow and decide what to do next. |
168 * @type {function(string)} | 180 * @type {function(string)} |
169 */ | 181 */ |
170 noPasswordCallback_: null, | 182 noPasswordCallback_: null, |
171 | 183 |
172 /** | 184 /** |
173 * The iframe container. | 185 * The iframe container. |
174 * @type {HTMLIFrameElement} | 186 * @type {HTMLIFrameElement} |
175 */ | 187 */ |
176 get frame() { | 188 get frame() { |
177 return this.frame_; | 189 return this.frame_; |
178 }, | 190 }, |
179 | 191 |
180 /** | 192 /** |
| 193 * Sets retrieveAuthenticatedUserEmailCallback_. |
| 194 * @type {function()} |
| 195 */ |
| 196 set retrieveAuthenticatedUserEmailCallback(callback) { |
| 197 this.retrieveAuthenticatedUserEmailCallback_ = callback; |
| 198 }, |
| 199 |
| 200 /** |
181 * Sets confirmPasswordCallback_. | 201 * Sets confirmPasswordCallback_. |
182 * @type {function()} | 202 * @type {function()} |
183 */ | 203 */ |
184 set confirmPasswordCallback(callback) { | 204 set confirmPasswordCallback(callback) { |
185 this.confirmPasswordCallback_ = callback; | 205 this.confirmPasswordCallback_ = callback; |
186 }, | 206 }, |
187 | 207 |
188 /** | 208 /** |
189 * Sets noPasswordCallback_. | 209 * Sets noPasswordCallback_. |
190 * @type {function()} | 210 * @type {function()} |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 */ | 275 */ |
256 verifyConfirmedPassword: function(password) { | 276 verifyConfirmedPassword: function(password) { |
257 var msg = { | 277 var msg = { |
258 method: 'verifyConfirmedPassword', | 278 method: 'verifyConfirmedPassword', |
259 password: password | 279 password: password |
260 }; | 280 }; |
261 this.frame_.contentWindow.postMessage(msg, AUTH_URL_BASE); | 281 this.frame_.contentWindow.postMessage(msg, AUTH_URL_BASE); |
262 }, | 282 }, |
263 | 283 |
264 /** | 284 /** |
| 285 * Sends the authenticated user's e-mail address to the auth extension. |
| 286 * @param {number} attemptToken The opaque token provided to the |
| 287 * retrieveAuthenticatedUserEmailCallback_. |
| 288 * @param {string} email The authenticated user's e-mail address. |
| 289 */ |
| 290 setAuthenticatedUserEmail: function(attemptToken, email) { |
| 291 var msg = { |
| 292 method: 'setAuthenticatedUserEmail', |
| 293 attemptToken: attemptToken, |
| 294 email: email |
| 295 }; |
| 296 this.frame_.contentWindow.postMessage(msg, AUTH_URL_BASE); |
| 297 }, |
| 298 |
| 299 /** |
265 * Invoked to process authentication success. | 300 * Invoked to process authentication success. |
266 * @param {Object} credentials Credential object to pass to success | 301 * @param {Object} credentials Credential object to pass to success |
267 * callback. | 302 * callback. |
268 * @private | 303 * @private |
269 */ | 304 */ |
270 onAuthSuccess_: function(credentials) { | 305 onAuthSuccess_: function(credentials) { |
271 if (this.successCallback_) | 306 if (this.successCallback_) |
272 this.successCallback_(credentials); | 307 this.successCallback_(credentials); |
273 cr.dispatchSimpleEvent(this, 'completed'); | 308 cr.dispatchSimpleEvent(this, 'completed'); |
274 }, | 309 }, |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 } | 353 } |
319 this.onAuthSuccess_({email: msg.email || this.email_, | 354 this.onAuthSuccess_({email: msg.email || this.email_, |
320 password: msg.password || this.password_, | 355 password: msg.password || this.password_, |
321 authCode: msg.authCode, | 356 authCode: msg.authCode, |
322 useOffline: msg.method == 'offlineLogin', | 357 useOffline: msg.method == 'offlineLogin', |
323 chooseWhatToSync: this.chooseWhatToSync_, | 358 chooseWhatToSync: this.chooseWhatToSync_, |
324 skipForNow: msg.skipForNow || false }); | 359 skipForNow: msg.skipForNow || false }); |
325 return; | 360 return; |
326 } | 361 } |
327 | 362 |
| 363 if (msg.method == 'retrieveAuthenticatedUserEmail') { |
| 364 if (this.retrieveAuthenticatedUserEmailCallback_) { |
| 365 this.retrieveAuthenticatedUserEmailCallback_(msg.attemptToken); |
| 366 } else { |
| 367 console.error( |
| 368 'GaiaAuthHost: Invalid retrieveAuthenticatedUserEmailCallback_.'); |
| 369 } |
| 370 return; |
| 371 } |
| 372 |
328 if (msg.method == 'confirmPassword') { | 373 if (msg.method == 'confirmPassword') { |
329 if (this.confirmPasswordCallback_) | 374 if (this.confirmPasswordCallback_) |
330 this.confirmPasswordCallback_(); | 375 this.confirmPasswordCallback_(); |
331 else | 376 else |
332 console.error('GaiaAuthHost: Invalid confirmPasswordCallback_.'); | 377 console.error('GaiaAuthHost: Invalid confirmPasswordCallback_.'); |
333 return; | 378 return; |
334 } | 379 } |
335 | 380 |
336 if (msg.method == 'noPassword') { | 381 if (msg.method == 'noPassword') { |
337 if (this.noPasswordCallback_) | 382 if (this.noPasswordCallback_) |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
391 | 436 |
392 GaiaAuthHost.SUPPORTED_PARAMS = SUPPORTED_PARAMS; | 437 GaiaAuthHost.SUPPORTED_PARAMS = SUPPORTED_PARAMS; |
393 GaiaAuthHost.LOCALIZED_STRING_PARAMS = LOCALIZED_STRING_PARAMS; | 438 GaiaAuthHost.LOCALIZED_STRING_PARAMS = LOCALIZED_STRING_PARAMS; |
394 GaiaAuthHost.AuthMode = AuthMode; | 439 GaiaAuthHost.AuthMode = AuthMode; |
395 GaiaAuthHost.AuthFlow = AuthFlow; | 440 GaiaAuthHost.AuthFlow = AuthFlow; |
396 | 441 |
397 return { | 442 return { |
398 GaiaAuthHost: GaiaAuthHost | 443 GaiaAuthHost: GaiaAuthHost |
399 }; | 444 }; |
400 }); | 445 }); |
OLD | NEW |