Skip to content
This repository has been archived by the owner. It is now read-only.

WIP: Add OAuth->browser plumbing. #1423

Closed
wants to merge 4 commits into from
Closed

WIP: Add OAuth->browser plumbing. #1423

wants to merge 4 commits into from

Conversation

@shane-tomlinson
Copy link
Member

@shane-tomlinson shane-tomlinson commented Jul 21, 2014

No description provided.

@shane-tomlinson shane-tomlinson changed the title Oauth msg 3 WIP: Add OAuth->browser plumbing. Jul 21, 2014
@shane-tomlinson
Copy link
Member Author

@shane-tomlinson shane-tomlinson commented Jul 21, 2014

@vladikoff - here we go!

return redirectParams && Url.searchParam(name, redirectParams);
},

completeOAuthNoInteraction: true,

This comment has been minimized.

@shane-tomlinson

shane-tomlinson Jul 21, 2014
Author Member

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 {

This comment has been minimized.

@shane-tomlinson

shane-tomlinson Jul 21, 2014
Author Member

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']);

This comment has been minimized.

@shane-tomlinson

shane-tomlinson Jul 21, 2014
Author Member

Hey, where'd the whitelist go?

This comment has been minimized.

@vladikoff

vladikoff Jul 21, 2014
Contributor

Hm not sure, did I move it?

This comment has been minimized.

@shane-tomlinson

shane-tomlinson Jul 21, 2014
Author Member

I think I did.

@pdehaan pdehaan added the WIP label Jul 21, 2014
});
},

_getRedirectParam: function(redirect, name) {

This comment has been minimized.

@shane-tomlinson

shane-tomlinson Jul 21, 2014
Author Member

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

This comment has been minimized.

@shane-tomlinson

shane-tomlinson Jul 21, 2014
Author Member

Should we rename source to something like sourceFlow or loginType?

This comment has been minimized.

@vladikoff

vladikoff Jul 21, 2014
Contributor

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;

This comment has been minimized.

@shane-tomlinson

shane-tomlinson Jul 21, 2014
Author Member

The FxADesktopChannel uses command whereas the CustomEventsChannel uses message :/

This comment has been minimized.

@vladikoff

vladikoff Jul 21, 2014
Contributor

Yeah, hm, WebChannel sends messages on webChannelIds

@@ -41,8 +40,7 @@ function (
Translator,
Session,
Url,
WebChannel,
FxDesktopChannel,
channelFactory,

This comment has been minimized.

@vladikoff

vladikoff Jul 21, 2014
Contributor

lowercase?

This comment has been minimized.

@shane-tomlinson

shane-tomlinson Jul 21, 2014
Author Member

Yeah, it's a singleton since it's a factory.

This comment has been minimized.

@shane-tomlinson

shane-tomlinson Jul 21, 2014
Author Member

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();

This comment has been minimized.

@vladikoff

vladikoff Jul 21, 2014
Contributor

probably should be called WebChannel

This comment has been minimized.

@shane-tomlinson

shane-tomlinson Jul 21, 2014
Author Member

I feel that WebChannel has a connotation that does not match the actual implementation.

This comment has been minimized.

@vladikoff

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

This comment has been minimized.

@shane-tomlinson

shane-tomlinson Jul 21, 2014
Author Member

That makes sense, can we call it the FirefoxWebChannel or MozillaWebChannel?

This comment has been minimized.

@vladikoff

vladikoff Jul 21, 2014
Contributor

In the content-server, I think so. FirefoxWebChannel sounds good to me. @ckarlof might have feedback on that.

This comment has been minimized.

@ckarlof

ckarlof Jul 22, 2014
Contributor

I'm fine with FirefoxWebChannel.

This comment has been minimized.

@ckarlof

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.

var data = e.detail;

if (data.webChannelId === this._webChannelId && data.message) {
this._messageCallbacks.forEach(function(callback) {

This comment has been minimized.

@shane-tomlinson

shane-tomlinson Jul 21, 2014
Author Member

forEach will blow up old IEs. Do we care?

@zaach
Copy link
Contributor

@zaach zaach commented Jul 21, 2014

👀 Keeping my eyes on this one.

@vladikoff
Copy link
Contributor

@vladikoff vladikoff commented Jul 21, 2014

@ckarlof, earlier from #1368

vladikoff and others added 2 commits Jul 9, 2014
…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'

This comment has been minimized.

@shane-tomlinson

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?


define(function () {
function WebChannel() {

This comment has been minimized.

@shane-tomlinson

shane-tomlinson Jul 22, 2014
Author Member

Maybe rename this to URLChannel?

This comment has been minimized.

@vladikoff

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?

This comment has been minimized.

@shane-tomlinson

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.

return serviceName;
},

_shouldSubmitWithoutInteraction: function () {

This comment has been minimized.

@shane-tomlinson

shane-tomlinson Jul 22, 2014
Author Member

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

This comment has been minimized.

@shane-tomlinson

shane-tomlinson Jul 22, 2014
Author Member

@vladikoff - does the webChannelId come from the URL search parameters?

This comment has been minimized.

@vladikoff

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)

function UrlChannel() {
}

_.extend(UrlChannel.prototype, Backbone.Events, {

This comment has been minimized.

@shane-tomlinson

shane-tomlinson Jul 22, 2014
Author Member

This doesn't really need Backbone.Events.

@shane-tomlinson
Copy link
Member Author

@shane-tomlinson shane-tomlinson commented Jul 23, 2014

Closing this in favor of a slimmed down version in #1437

@shane-tomlinson shane-tomlinson deleted the oauth-msg-3 branch Oct 23, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

5 participants