WIP: Add OAuth->browser plumbing. #1423
Conversation
|
@vladikoff - here we go! |
| return redirectParams && Url.searchParam(name, redirectParams); | ||
| }, | ||
|
|
||
| completeOAuthNoInteraction: true, |
shane-tomlinson
Jul 21, 2014
Author
Member
Not sure about this name.
Not sure about this name.
| // A channel that attempts to listen for messages from the browser. | ||
| // unsure of how this is different from FxDesktopChannel | ||
| channel = new CustomEventsChannel(); | ||
| } else { |
shane-tomlinson
Jul 21, 2014
Author
Member
I'm going to plug the iframe channel in right here.
I'm going to plug the iframe channel in right here.
| // params listed in: | ||
| // https://github.com/mozilla/fxa-oauth-server/blob/master/docs/api.md#post-v1authorization | ||
| params = Url.searchParams(this.window.location.search, | ||
| ['client_id', 'redirect_uri', 'state', 'scope', 'action']); |
shane-tomlinson
Jul 21, 2014
Author
Member
Hey, where'd the whitelist go?
Hey, where'd the whitelist go?
vladikoff
Jul 21, 2014
Contributor
Hm not sure, did I move it?
Hm not sure, did I move it?
shane-tomlinson
Jul 21, 2014
Author
Member
I think I did.
I think I did.
| }); | ||
| }, | ||
|
|
||
| _getRedirectParam: function(redirect, name) { |
shane-tomlinson
Jul 21, 2014
Author
Member
Is this needed?
Is this needed?
| @@ -88,7 +102,9 @@ function (_, BaseView, FormView, Template, Session, Xss, Strings, ServiceMixin, | |||
|
|
|||
| submit: function () { | |||
| if (this.isOAuthSameBrowser()) { | |||
| return this.finishOAuthFlow(); | |||
| return this.finishOAuthFlow({ | |||
| source: this.type | |||
shane-tomlinson
Jul 21, 2014
Author
Member
Should we rename source to something like sourceFlow or loginType?
Should we rename source to something like sourceFlow or loginType?
vladikoff
Jul 21, 2014
Contributor
sourceFlow works for me
sourceFlow works for me
| @@ -38,7 +38,7 @@ function (_, Backbone) { | |||
|
|
|||
| _.extend(WindowMock.prototype, Backbone.Events, { | |||
| dispatchEvent: function (event) { | |||
| var msg = event.detail.command; | |||
| var msg = event.detail.command || event.detail.message; | |||
shane-tomlinson
Jul 21, 2014
Author
Member
The FxADesktopChannel uses command whereas the CustomEventsChannel uses message :/
The FxADesktopChannel uses command whereas the CustomEventsChannel uses message :/
vladikoff
Jul 21, 2014
Contributor
Yeah, hm, WebChannel sends messages on webChannelIds
Yeah, hm, WebChannel sends messages on webChannelIds
| @@ -41,8 +40,7 @@ function ( | |||
| Translator, | |||
| Session, | |||
| Url, | |||
| WebChannel, | |||
| FxDesktopChannel, | |||
| channelFactory, | |||
vladikoff
Jul 21, 2014
Contributor
lowercase?
lowercase?
shane-tomlinson
Jul 21, 2014
Author
Member
Yeah, it's a singleton since it's a factory.
Yeah, it's a singleton since it's a factory.
shane-tomlinson
Jul 21, 2014
Author
Member
open to suggestions for clarity.
open to suggestions for clarity.
| } else if (options.webChannelId) { | ||
| // A channel that attempts to listen for messages from the browser. | ||
| // unsure of how this is different from FxDesktopChannel | ||
| channel = new CustomEventsChannel(); |
vladikoff
Jul 21, 2014
Contributor
probably should be called WebChannel
probably should be called WebChannel
shane-tomlinson
Jul 21, 2014
Author
Member
I feel that WebChannel has a connotation that does not match the actual implementation.
I feel that WebChannel has a connotation that does not match the actual implementation.
vladikoff
Jul 21, 2014
Contributor
We are trying to keep it similar to what is going into the browser module.
See draft https://developer.mozilla.org/en-US/docs/Mozilla/JavaScript_code_modules/WebChannel.jsm
We are trying to keep it similar to what is going into the browser module.
See draft https://developer.mozilla.org/en-US/docs/Mozilla/JavaScript_code_modules/WebChannel.jsm
shane-tomlinson
Jul 21, 2014
Author
Member
That makes sense, can we call it the FirefoxWebChannel or MozillaWebChannel?
That makes sense, can we call it the FirefoxWebChannel or MozillaWebChannel?
vladikoff
Jul 21, 2014
Contributor
In the content-server, I think so. FirefoxWebChannel sounds good to me. @ckarlof might have feedback on that.
In the content-server, I think so. FirefoxWebChannel sounds good to me. @ckarlof might have feedback on that.
ckarlof
Jul 22, 2014
Contributor
I'm fine with FirefoxWebChannel.
I'm fine with FirefoxWebChannel.
ckarlof
Jul 22, 2014
Contributor
I don't know about this factory for channels. It seems like an unnecessary level of abstraction, especially since the API is weird. Sometimes it looks at options.context and otherwise options.webChannelId. I would just keep app-start the same by invoking the constructors and have _createChannel just call the WebChannel constructor. If a factory becomes necessary in the future to manage complexity we can add it. Right now it seems like it makes something simple more complex.
I don't know about this factory for channels. It seems like an unnecessary level of abstraction, especially since the API is weird. Sometimes it looks at options.context and otherwise options.webChannelId. I would just keep app-start the same by invoking the constructors and have _createChannel just call the WebChannel constructor. If a factory becomes necessary in the future to manage complexity we can add it. Right now it seems like it makes something simple more complex.
| var data = e.detail; | ||
|
|
||
| if (data.webChannelId === this._webChannelId && data.message) { | ||
| this._messageCallbacks.forEach(function(callback) { |
shane-tomlinson
Jul 21, 2014
Author
Member
forEach will blow up old IEs. Do we care?
forEach will blow up old IEs. Do we care?
|
|
…d simplify the Oauth completion logic. * Appease jscs and jshint * Extract all channel creation logic into lib/channels/factory.js * Rename the WebChannel to FirefoxWebChannel * Simplify service-mixin by checking whether a channel has a completeOAuth function. If it does, the channel knows what to do with the OAuth result and can complete the transaction. If the function returns a promise, it is asynchronous. * Add completeOAuth to the FirefoxWeb channel. * Create a 'web' channel that redirects after oauth completion. * in service-mixin.js, Do NOT submit the form from context because context is called for each translation and could cause multiple submissions. Instead call submit from afterRender. * rename fx-desktop.js -> fx_desktop.js * rename web.js-> fx_web.js
| command: 'oauth_complete', | ||
| state: state, | ||
| code: code, | ||
| closeWindow: source === 'signin' |
shane-tomlinson
Jul 22, 2014
Author
Member
It seems a bit strange to order the receiver to close the window. Does it make more sense to send source to the receiver and let them decide what to do?
It seems a bit strange to order the receiver to close the window. Does it make more sense to send source to the receiver and let them decide what to do?
|
|
||
| define(function () { | ||
| function WebChannel() { |
shane-tomlinson
Jul 22, 2014
Author
Member
Maybe rename this to URLChannel?
Maybe rename this to URLChannel?
vladikoff
Jul 22, 2014
Contributor
Sorry I don't think that will work because the browser api is called "WebChannel", this would probably be confusing. We can go with FirefoxWebChannel, could be the least confusing. However, what if we want to write some add-ons for Chrome or iOS and use this WebChannel to communicate?
Sorry I don't think that will work because the browser api is called "WebChannel", this would probably be confusing. We can go with FirefoxWebChannel, could be the least confusing. However, what if we want to write some add-ons for Chrome or iOS and use this WebChannel to communicate?
shane-tomlinson
Jul 22, 2014
Author
Member
On 22/07/2014 16:35, Vlad Filippov wrote:
In app/scripts/lib/channels/web.js:
-define(function () {
function WebChannel() {
Sorry I don't think that will work because the browser api is called
"WebChannel", this would probably be confusing. We can go with
|FirefoxWebChannel|, could be the least confusing. However, what if we
want to write some add-ons for Chrome or iOS and use this WebChannel to
communicate?
—
Reply to this email directly or view it on GitHub
https://github.com/mozilla/fxa-content-server/pull/1423/files#r15235006.
Looking at old code? The most current has custom_event.js renamed to
fx_web.js with the module named FirefoxWebChannel. web.js is renamed to
null.js and NullChannel.
On 22/07/2014 16:35, Vlad Filippov wrote:
In app/scripts/lib/channels/web.js:
-define(function () {
function WebChannel() {Sorry I don't think that will work because the browser api is called
"WebChannel", this would probably be confusing. We can go with
|FirefoxWebChannel|, could be the least confusing. However, what if we
want to write some add-ons for Chrome or iOS and use this WebChannel to
communicate?—
Reply to this email directly or view it on GitHub
https://github.com/mozilla/fxa-content-server/pull/1423/files#r15235006.
Looking at old code? The most current has custom_event.js renamed to
fx_web.js with the module named FirefoxWebChannel. web.js is renamed to
null.js and NullChannel.
| return serviceName; | ||
| }, | ||
|
|
||
| _shouldSubmitWithoutInteraction: function () { |
shane-tomlinson
Jul 22, 2014
Author
Member
Put this into the service-mixin
Put this into the service-mixin
* Add `completeOAuthError` to the relevant channels. * Add a `URLChannel` which passes OAuth information over the URL. * Attempt to simplify how the spinner is presented in the service-mixin.
| if (this._oAuthParams.webChannelId) { | ||
| channel = new FxWebChannel(); | ||
| channel.init({ | ||
| webChannelId: this._oAuthParams.webChannelId |
vladikoff
Jul 22, 2014
Contributor
Yeap. It is also saved into _oAuthParams because we want to be able to finish the OAuth flow in a new tab (same browser)
Yeap. It is also saved into _oAuthParams because we want to be able to finish the OAuth flow in a new tab (same browser)
| function UrlChannel() { | ||
| } | ||
|
|
||
| _.extend(UrlChannel.prototype, Backbone.Events, { |
shane-tomlinson
Jul 22, 2014
Author
Member
This doesn't really need Backbone.Events.
This doesn't really need Backbone.Events.
|
Closing this in favor of a slimmed down version in #1437 |
No description provided.