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 /** | 5 /** |
6 * Authenticator class wraps the communications between Gaia and its host. | 6 * Authenticator class wraps the communications between Gaia and its host. |
7 */ | 7 */ |
8 function Authenticator() { | 8 function Authenticator() { |
9 } | 9 } |
10 | 10 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
56 // when support for key types other than plain text password is added. | 56 // when support for key types other than plain text password is added. |
57 passwordBytes_: null, | 57 passwordBytes_: null, |
58 | 58 |
59 attemptToken_: null, | 59 attemptToken_: null, |
60 | 60 |
61 // Input params from extension initialization URL. | 61 // Input params from extension initialization URL. |
62 inputLang_: undefined, | 62 inputLang_: undefined, |
63 intputEmail_: undefined, | 63 intputEmail_: undefined, |
64 | 64 |
65 isSAMLFlow_: false, | 65 isSAMLFlow_: false, |
66 isSAMLEnabled_: false, | |
67 supportChannel_: null, | 66 supportChannel_: null, |
68 | 67 |
69 GAIA_URL: 'https://accounts.google.com/', | 68 GAIA_URL: 'https://accounts.google.com/', |
70 GAIA_PAGE_PATH: 'ServiceLogin?skipvpage=true&sarp=1&rm=hide', | 69 GAIA_PAGE_PATH: 'ServiceLogin?skipvpage=true&sarp=1&rm=hide', |
71 PARENT_PAGE: 'chrome://oobe/', | 70 PARENT_PAGE: 'chrome://oobe/', |
72 SERVICE_ID: 'chromeoslogin', | 71 SERVICE_ID: 'chromeoslogin', |
73 CONTINUE_URL: Authenticator.THIS_EXTENSION_ORIGIN + '/success.html', | 72 CONTINUE_URL: Authenticator.THIS_EXTENSION_ORIGIN + '/success.html', |
74 CONSTRAINED_FLOW_SOURCE: 'chrome', | 73 CONSTRAINED_FLOW_SOURCE: 'chrome', |
75 | 74 |
76 initialize: function() { | 75 initialize: function() { |
77 var params = getUrlSearchParams(location.search); | 76 var params = getUrlSearchParams(location.search); |
78 this.parentPage_ = params.parentPage || this.PARENT_PAGE; | 77 this.parentPage_ = params.parentPage || this.PARENT_PAGE; |
79 this.gaiaUrl_ = params.gaiaUrl || this.GAIA_URL; | 78 this.gaiaUrl_ = params.gaiaUrl || this.GAIA_URL; |
80 this.gaiaPath_ = params.gaiaPath || this.GAIA_PAGE_PATH; | 79 this.gaiaPath_ = params.gaiaPath || this.GAIA_PAGE_PATH; |
81 this.inputLang_ = params.hl; | 80 this.inputLang_ = params.hl; |
82 this.inputEmail_ = params.email; | 81 this.inputEmail_ = params.email; |
83 this.service_ = params.service || this.SERVICE_ID; | 82 this.service_ = params.service || this.SERVICE_ID; |
84 this.continueUrl_ = params.continueUrl || this.CONTINUE_URL; | 83 this.continueUrl_ = params.continueUrl || this.CONTINUE_URL; |
85 this.desktopMode_ = params.desktopMode == '1'; | 84 this.desktopMode_ = params.desktopMode == '1'; |
86 this.isConstrainedWindow_ = params.constrained == '1'; | 85 this.isConstrainedWindow_ = params.constrained == '1'; |
87 this.initialFrameUrl_ = params.frameUrl || this.constructInitialFrameUrl_(); | 86 this.initialFrameUrl_ = params.frameUrl || this.constructInitialFrameUrl_(); |
88 this.initialFrameUrlWithoutParams_ = stripParams(this.initialFrameUrl_); | 87 this.initialFrameUrlWithoutParams_ = stripParams(this.initialFrameUrl_); |
89 | 88 |
90 document.addEventListener('DOMContentLoaded', this.onPageLoad_.bind(this)); | 89 document.addEventListener('DOMContentLoaded', this.onPageLoad_.bind(this)); |
91 if (!this.desktopMode_) { | |
92 // SAML is always enabled in desktop mode, thus no need to listen for | |
93 // enableSAML event. | |
94 document.addEventListener('enableSAML', this.onEnableSAML_.bind(this)); | |
95 } | |
96 }, | 90 }, |
97 | 91 |
98 isGaiaMessage_: function(msg) { | 92 isGaiaMessage_: function(msg) { |
99 // Not quite right, but good enough. | 93 // Not quite right, but good enough. |
100 return this.gaiaUrl_.indexOf(msg.origin) == 0 || | 94 return this.gaiaUrl_.indexOf(msg.origin) == 0 || |
101 this.GAIA_URL.indexOf(msg.origin) == 0; | 95 this.GAIA_URL.indexOf(msg.origin) == 0; |
102 }, | 96 }, |
103 | 97 |
104 isInternalMessage_: function(msg) { | 98 isInternalMessage_: function(msg) { |
105 return msg.origin == Authenticator.THIS_EXTENSION_ORIGIN; | 99 return msg.origin == Authenticator.THIS_EXTENSION_ORIGIN; |
(...skipping 16 matching lines...) Expand all Loading... | |
122 url = appendParam(url, 'source', this.CONSTRAINED_FLOW_SOURCE); | 116 url = appendParam(url, 'source', this.CONSTRAINED_FLOW_SOURCE); |
123 return url; | 117 return url; |
124 }, | 118 }, |
125 | 119 |
126 onPageLoad_: function() { | 120 onPageLoad_: function() { |
127 window.addEventListener('message', this.onMessage.bind(this), false); | 121 window.addEventListener('message', this.onMessage.bind(this), false); |
128 | 122 |
129 var gaiaFrame = $('gaia-frame'); | 123 var gaiaFrame = $('gaia-frame'); |
130 gaiaFrame.src = this.initialFrameUrl_; | 124 gaiaFrame.src = this.initialFrameUrl_; |
131 | 125 |
132 if (this.desktopMode_) { | 126 var handler = function() { |
133 var handler = function() { | 127 if (this.desktopMode_) |
134 this.onLoginUILoaded_(); | 128 this.onLoginUILoaded_(); |
135 gaiaFrame.removeEventListener('load', handler); | 129 gaiaFrame.removeEventListener('load', handler); |
136 | 130 |
137 this.initDesktopChannel_(); | 131 this.initSupportChannel_(); |
138 }.bind(this); | 132 }.bind(this); |
139 gaiaFrame.addEventListener('load', handler); | 133 gaiaFrame.addEventListener('load', handler); |
140 } | |
141 }, | 134 }, |
142 | 135 |
143 initDesktopChannel_: function() { | 136 initSupportChannel_: function() { |
144 this.supportChannel_ = new Channel(); | 137 this.supportChannel_ = new Channel(); |
145 this.supportChannel_.connect('authMain'); | 138 this.supportChannel_.connect('authMain'); |
146 | 139 |
147 var channelConnected = false; | 140 var channelConnected = false; |
148 this.supportChannel_.registerMessage('channelConnected', function() { | 141 this.supportChannel_.registerMessage('channelConnected', function() { |
149 channelConnected = true; | 142 channelConnected = true; |
150 | 143 |
151 this.supportChannel_.send({ | 144 if (this.desktopMode_) { |
152 name: 'initDesktopFlow', | 145 this.supportChannel_.send({ |
153 gaiaUrl: this.gaiaUrl_, | 146 name: 'initDesktopFlow', |
154 continueUrl: stripParams(this.continueUrl_), | 147 gaiaUrl: this.gaiaUrl_, |
155 isConstrainedWindow: this.isConstrainedWindow_ | 148 continueUrl: stripParams(this.continueUrl_), |
156 }); | 149 isConstrainedWindow: this.isConstrainedWindow_ |
157 this.supportChannel_.registerMessage( | 150 }); |
158 'switchToFullTab', this.switchToFullTab_.bind(this)); | 151 this.supportChannel_.registerMessage( |
159 this.supportChannel_.registerMessage( | 152 'switchToFullTab', this.switchToFullTab_.bind(this)); |
160 'completeLogin', this.completeLogin_.bind(this)); | 153 this.supportChannel_.registerMessage( |
161 | 154 'completeLogin', this.completeLogin_.bind(this)); |
162 this.onEnableSAML_(); | 155 } |
156 this.initSAML_(); | |
163 }.bind(this)); | 157 }.bind(this)); |
164 | 158 |
165 window.setTimeout(function() { | 159 window.setTimeout(function() { |
166 if (!channelConnected) { | 160 if (!channelConnected) { |
167 // Re-initialize the channel if it is not connected properly, e.g. | 161 // Re-initialize the channel if it is not connected properly, e.g. |
168 // connect may be called before background script started running. | 162 // connect may be called before background script started running. |
169 this.initDesktopChannel_(); | 163 this.initDesktopChannel_(); |
bartfab (slow)
2014/07/14 10:12:40
This calls initDesktopChannel_(), which no longer
dzhioev (left Google)
2014/07/15 18:34:07
Done.
| |
170 } | 164 } |
171 }.bind(this), 200); | 165 }.bind(this), 200); |
dzhioev (left Google)
2014/07/11 13:54:25
Hui, why this check is needed? On Chrome OS we con
guohui
2014/07/11 19:29:36
initSupportChannel_ is called from onPageLoad_ whi
dzhioev (left Google)
2014/07/15 18:34:08
You are right.
Note that we have potential race he
| |
172 }, | 166 }, |
173 | 167 |
174 /** | 168 /** |
175 * Invoked when the login UI is initialized or reset. | 169 * Invoked when the login UI is initialized or reset. |
176 */ | 170 */ |
177 onLoginUILoaded_: function() { | 171 onLoginUILoaded_: function() { |
178 var msg = { | 172 var msg = { |
179 'method': 'loginUILoaded' | 173 'method': 'loginUILoaded' |
180 }; | 174 }; |
181 window.parent.postMessage(msg, this.parentPage_); | 175 window.parent.postMessage(msg, this.parentPage_); |
(...skipping 21 matching lines...) Expand all Loading... | |
203 'method': 'completeLogin', | 197 'method': 'completeLogin', |
204 'email': (opt_extraMsg && opt_extraMsg.email) || this.email_, | 198 'email': (opt_extraMsg && opt_extraMsg.email) || this.email_, |
205 'password': (opt_extraMsg && opt_extraMsg.password) || | 199 'password': (opt_extraMsg && opt_extraMsg.password) || |
206 this.passwordBytes_, | 200 this.passwordBytes_, |
207 'usingSAML': this.isSAMLFlow_, | 201 'usingSAML': this.isSAMLFlow_, |
208 'chooseWhatToSync': this.chooseWhatToSync_ || false, | 202 'chooseWhatToSync': this.chooseWhatToSync_ || false, |
209 'skipForNow': opt_extraMsg && opt_extraMsg.skipForNow, | 203 'skipForNow': opt_extraMsg && opt_extraMsg.skipForNow, |
210 'sessionIndex': opt_extraMsg && opt_extraMsg.sessionIndex | 204 'sessionIndex': opt_extraMsg && opt_extraMsg.sessionIndex |
211 }; | 205 }; |
212 window.parent.postMessage(msg, this.parentPage_); | 206 window.parent.postMessage(msg, this.parentPage_); |
213 if (this.isSAMLEnabled_) | 207 this.supportChannel_.send({name: 'resetAuth'}); |
214 this.supportChannel_.send({name: 'resetAuth'}); | |
215 }, | 208 }, |
216 | 209 |
217 /** | 210 /** |
218 * Invoked when 'enableSAML' event is received to initialize SAML support on | 211 * Invoded when support channel is connected. |
bartfab (slow)
2014/07/14 10:12:40
Nit: s/Invoded/Invoked/
dzhioev (left Google)
2014/07/15 18:34:08
Done.
| |
219 * Chrome OS, or when initDesktopChannel_ is called on desktop. | |
220 */ | 212 */ |
221 onEnableSAML_: function() { | 213 initSAML_: function() { |
222 this.isSAMLEnabled_ = true; | |
223 this.isSAMLFlow_ = false; | 214 this.isSAMLFlow_ = false; |
224 | 215 |
225 if (!this.supportChannel_) { | |
226 this.supportChannel_ = new Channel(); | |
227 this.supportChannel_.connect('authMain'); | |
228 } | |
229 | |
230 this.supportChannel_.registerMessage( | 216 this.supportChannel_.registerMessage( |
231 'onAuthPageLoaded', this.onAuthPageLoaded_.bind(this)); | 217 'onAuthPageLoaded', this.onAuthPageLoaded_.bind(this)); |
232 this.supportChannel_.registerMessage( | 218 this.supportChannel_.registerMessage( |
233 'onInsecureContentBlocked', this.onInsecureContentBlocked_.bind(this)); | 219 'onInsecureContentBlocked', this.onInsecureContentBlocked_.bind(this)); |
234 this.supportChannel_.registerMessage( | 220 this.supportChannel_.registerMessage( |
235 'apiCall', this.onAPICall_.bind(this)); | 221 'apiCall', this.onAPICall_.bind(this)); |
236 this.supportChannel_.send({ | 222 this.supportChannel_.send({ |
237 name: 'setGaiaUrl', | 223 name: 'setGaiaUrl', |
238 gaiaUrl: this.gaiaUrl_ | 224 gaiaUrl: this.gaiaUrl_ |
239 }); | 225 }); |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
393 }, | 379 }, |
394 | 380 |
395 onMessage: function(e) { | 381 onMessage: function(e) { |
396 var msg = e.data; | 382 var msg = e.data; |
397 if (msg.method == 'attemptLogin' && this.isGaiaMessage_(e)) { | 383 if (msg.method == 'attemptLogin' && this.isGaiaMessage_(e)) { |
398 this.email_ = msg.email; | 384 this.email_ = msg.email; |
399 this.passwordBytes_ = msg.password; | 385 this.passwordBytes_ = msg.password; |
400 this.attemptToken_ = msg.attemptToken; | 386 this.attemptToken_ = msg.attemptToken; |
401 this.chooseWhatToSync_ = msg.chooseWhatToSync; | 387 this.chooseWhatToSync_ = msg.chooseWhatToSync; |
402 this.isSAMLFlow_ = false; | 388 this.isSAMLFlow_ = false; |
403 if (this.isSAMLEnabled_) | 389 this.supportChannel_.send({name: 'startAuth'}); |
404 this.supportChannel_.send({name: 'startAuth'}); | |
405 } else if (msg.method == 'clearOldAttempts' && this.isGaiaMessage_(e)) { | 390 } else if (msg.method == 'clearOldAttempts' && this.isGaiaMessage_(e)) { |
406 this.email_ = null; | 391 this.email_ = null; |
407 this.passwordBytes_ = null; | 392 this.passwordBytes_ = null; |
408 this.attemptToken_ = null; | 393 this.attemptToken_ = null; |
409 this.isSAMLFlow_ = false; | 394 this.isSAMLFlow_ = false; |
410 this.onLoginUILoaded_(); | 395 this.onLoginUILoaded_(); |
411 if (this.isSAMLEnabled_) | 396 this.supportChannel_.send({name: 'resetAuth'}); |
412 this.supportChannel_.send({name: 'resetAuth'}); | |
413 } else if (msg.method == 'setAuthenticatedUserEmail' && | 397 } else if (msg.method == 'setAuthenticatedUserEmail' && |
414 this.isParentMessage_(e)) { | 398 this.isParentMessage_(e)) { |
415 if (this.attemptToken_ == msg.attemptToken) { | 399 if (this.attemptToken_ == msg.attemptToken) { |
416 this.email_ = msg.email; | 400 this.email_ = msg.email; |
417 this.maybeCompleteSAMLLogin_(); | 401 this.maybeCompleteSAMLLogin_(); |
418 } | 402 } |
419 } else if (msg.method == 'confirmLogin' && this.isInternalMessage_(e)) { | 403 } else if (msg.method == 'confirmLogin' && this.isInternalMessage_(e)) { |
420 if (this.attemptToken_ == msg.attemptToken) | 404 if (this.attemptToken_ == msg.attemptToken) |
421 this.onConfirmLogin_(); | 405 this.onConfirmLogin_(); |
422 else | 406 else |
423 console.error('Authenticator.onMessage: unexpected attemptToken!?'); | 407 console.error('Authenticator.onMessage: unexpected attemptToken!?'); |
424 } else if (msg.method == 'verifyConfirmedPassword' && | 408 } else if (msg.method == 'verifyConfirmedPassword' && |
425 this.isParentMessage_(e)) { | 409 this.isParentMessage_(e)) { |
426 this.onVerifyConfirmedPassword_(msg.password); | 410 this.onVerifyConfirmedPassword_(msg.password); |
427 } else if (msg.method == 'redirectToSignin' && | 411 } else if (msg.method == 'redirectToSignin' && |
428 this.isParentMessage_(e)) { | 412 this.isParentMessage_(e)) { |
429 $('gaia-frame').src = this.constructInitialFrameUrl_(); | 413 $('gaia-frame').src = this.constructInitialFrameUrl_(); |
430 } else { | 414 } else { |
431 console.error('Authenticator.onMessage: unknown message + origin!?'); | 415 console.error('Authenticator.onMessage: unknown message + origin!?'); |
432 } | 416 } |
433 } | 417 } |
434 }; | 418 }; |
435 | 419 |
436 Authenticator.getInstance().initialize(); | 420 Authenticator.getInstance().initialize(); |
OLD | NEW |