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 login.createScreen('OAuthEnrollmentScreen', 'oauth-enrollment', function() { | 5 login.createScreen('OAuthEnrollmentScreen', 'oauth-enrollment', function() { |
6 /** @const */ var STEP_SIGNIN = 'signin'; | 6 /** @const */ var STEP_SIGNIN = 'signin'; |
7 /** @const */ var STEP_WORKING = 'working'; | 7 /** @const */ var STEP_WORKING = 'working'; |
8 /** @const */ var STEP_ERROR = 'error'; | 8 /** @const */ var STEP_ERROR = 'error'; |
9 /** @const */ var STEP_EXPLAIN = 'explain'; | 9 /** @const */ var STEP_EXPLAIN = 'explain'; |
10 /** @const */ var STEP_SUCCESS = 'success'; | 10 /** @const */ var STEP_SUCCESS = 'success'; |
11 | 11 |
12 return { | 12 return { |
13 EXTERNAL_API: [ | 13 EXTERNAL_API: [ |
14 'setIsAutoEnrollment', | 14 'setIsAutoEnrollment', |
15 'showStep', | 15 'showStep', |
16 'showError', | 16 'showError', |
17 'showWorking', | 17 'showWorking', |
| 18 'setAuthenticatedUserEmail', |
18 ], | 19 ], |
19 | 20 |
20 /** | 21 /** |
21 * URL to load in the sign in frame. | 22 * URL to load in the sign in frame. |
22 */ | 23 */ |
23 signInUrl_: null, | 24 signInUrl_: null, |
24 | 25 |
25 /** | 26 /** |
26 * Whether this is a manual or auto enrollment. | 27 * Whether this is a manual or auto enrollment. |
27 */ | 28 */ |
(...skipping 13 matching lines...) Expand all Loading... |
41 * Dialog to confirm that auto-enrollment should really be cancelled. | 42 * Dialog to confirm that auto-enrollment should really be cancelled. |
42 * This is only created the first time it's used. | 43 * This is only created the first time it's used. |
43 */ | 44 */ |
44 confirmDialog_: null, | 45 confirmDialog_: null, |
45 | 46 |
46 /** | 47 /** |
47 * The current step. This is the last value passed to showStep(). | 48 * The current step. This is the last value passed to showStep(). |
48 */ | 49 */ |
49 currentStep_: null, | 50 currentStep_: null, |
50 | 51 |
| 52 /** |
| 53 * Opaque token used to correlate request and response while retrieving the |
| 54 * authenticated user's e-mail address from GAIA. |
| 55 */ |
| 56 attemptToken_: null, |
| 57 |
51 /** @override */ | 58 /** @override */ |
52 decorate: function() { | 59 decorate: function() { |
53 window.addEventListener('message', | 60 window.addEventListener('message', |
54 this.onMessage_.bind(this), false); | 61 this.onMessage_.bind(this), false); |
55 $('oauth-enroll-error-retry').addEventListener('click', | 62 $('oauth-enroll-error-retry').addEventListener('click', |
56 this.doRetry_.bind(this)); | 63 this.doRetry_.bind(this)); |
57 var links = document.querySelectorAll('.oauth-enroll-explain-link'); | 64 var links = document.querySelectorAll('.oauth-enroll-explain-link'); |
58 for (var i = 0; i < links.length; i++) { | 65 for (var i = 0; i < links.length; i++) { |
59 links[i].addEventListener('click', | 66 links[i].addEventListener('click', |
60 this.showStep.bind(this, STEP_EXPLAIN)); | 67 this.showStep.bind(this, STEP_EXPLAIN)); |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 /** | 233 /** |
227 * Sets a progressing message and switches to the working screen. | 234 * Sets a progressing message and switches to the working screen. |
228 * @param {string} message the progress message. | 235 * @param {string} message the progress message. |
229 */ | 236 */ |
230 showWorking: function(message) { | 237 showWorking: function(message) { |
231 $('oauth-enroll-working-message').textContent = message; | 238 $('oauth-enroll-working-message').textContent = message; |
232 this.showStep(STEP_WORKING); | 239 this.showStep(STEP_WORKING); |
233 }, | 240 }, |
234 | 241 |
235 /** | 242 /** |
| 243 * Invoked when the authenticated user's e-mail address has been retrieved. |
| 244 * This completes SAML authentication. |
| 245 * @param {number} attemptToken An opaque token used to correlate this |
| 246 * method invocation with the corresponding request to retrieve the |
| 247 * user's e-mail address. |
| 248 * @param {string} email The authenticated user's e-mail address. |
| 249 */ |
| 250 setAuthenticatedUserEmail: function(attemptToken, email) { |
| 251 if (this.attemptToken_ == attemptToken) |
| 252 chrome.send('oauthEnrollCompleteLogin', [email]); |
| 253 }, |
| 254 |
| 255 /** |
236 * Handler for cancellations of an enforced auto-enrollment. | 256 * Handler for cancellations of an enforced auto-enrollment. |
237 */ | 257 */ |
238 cancelAutoEnrollment: function() { | 258 cancelAutoEnrollment: function() { |
239 // Check if this is forced enrollment flow for a kiosk app. | 259 // Check if this is forced enrollment flow for a kiosk app. |
240 if (this.preventCancellation_) | 260 if (this.preventCancellation_) |
241 return; | 261 return; |
242 | 262 |
243 // The dialog to confirm cancellation of auto-enrollment is only shown | 263 // The dialog to confirm cancellation of auto-enrollment is only shown |
244 // if this is an auto-enrollment, and if the user is currently in the | 264 // if this is an auto-enrollment, and if the user is currently in the |
245 // 'explain' step. | 265 // 'explain' step. |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 /** | 309 /** |
290 * Event handler for HTML5 messages. | 310 * Event handler for HTML5 messages. |
291 * @param {Object} m HTML5 message. | 311 * @param {Object} m HTML5 message. |
292 */ | 312 */ |
293 onMessage_: function(m) { | 313 onMessage_: function(m) { |
294 if (!this.isSigninMessage_(m)) | 314 if (!this.isSigninMessage_(m)) |
295 return; | 315 return; |
296 | 316 |
297 var msg = m.data; | 317 var msg = m.data; |
298 | 318 |
299 // 'completeLogin' for full gaia signin flow. For SAML case, | 319 if (msg.method == 'completeLogin') { |
300 // 'confirmPassword' is sent after authentication. Since enrollment | 320 // A user has successfully authenticated via regular GAIA. |
301 // does not need the actual password, this is treated the same as | |
302 // 'completeLogin'. | |
303 if (msg.method == 'completeLogin' || msg.method == 'confirmPassword') | |
304 chrome.send('oauthEnrollCompleteLogin', [msg.email]); | 321 chrome.send('oauthEnrollCompleteLogin', [msg.email]); |
| 322 } |
| 323 |
| 324 if (msg.method == 'retrieveAuthenticatedUserEmail') { |
| 325 // A user has successfully authenticated via SAML. However, the user's |
| 326 // identity is not known. Instead of reporting success immediately, |
| 327 // retrieve the user's e-mail address first. |
| 328 this.attemptToken_ = msg.attemptToken; |
| 329 this.showWorking(null); |
| 330 chrome.send('oauthEnrollRetrieveAuthenticatedUserEmail', |
| 331 [msg.attemptToken]); |
| 332 } |
305 } | 333 } |
306 }; | 334 }; |
307 }); | 335 }); |
308 | 336 |
OLD | NEW |