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

WIP feat(oauth): signal action=signup or action=signin at end of oauth flow. #2369

Closed
wants to merge 1 commit into from

Conversation

@rfk
Copy link
Member

@rfk rfk commented May 1, 2015

Here's my WIP experiment with signalling "action=signup" or "action=signin" at the end of the OAuth flow. Most definitely now ready yet, but thought I'd put it out there early.

Fixes #2345

@rfk rfk added WIP pocket and removed WIP labels May 1, 2015
@rfk rfk force-pushed the rfk/signal-auth-type branch from 0cf2255 to 2975cab May 1, 2015

if (result.error) {
// really, we should be parsing the URL and adding the error
// parameter. That requires more code than this.
var separator = redirectTo.indexOf('?') === -1 ? '?' : '&';
separator = redirectTo.indexOf('?') === -1 ? '?' : '&';

This comment has been minimized.

@shane-tomlinson

shane-tomlinson May 3, 2015
Member

Maybe it's time to parse the URI, then make use of lib.js->objToSearchString, this is starting to look a bit out of control. Not sure how much more effort that would be.

This comment has been minimized.

@rfk

rfk May 3, 2015
Author Member

yes, it's definitely time

@@ -103,13 +103,13 @@ define([
// The slight delay is to allow the functional tests time to bind
// event handlers before the flow completes.
var self = this;
return p().delay(100).then(_.bind(self.finishOAuthFlow, self, account));
return p().delay(100).then(_.bind(self.finishOAuthFlow, self, account, { action: 'signup' }));

This comment has been minimized.

@shane-tomlinson

shane-tomlinson May 3, 2015
Member

nit: this line wraps in GitHub side by side view, can you split it before the .delay(100) or before the .then?

@@ -119,6 +119,8 @@ define([
},

afterSignIn: function (account, additionalResultData) {
// Signal to the RP that this was an existing account sign-in.
additionalResultData.action = 'signin';

This comment has been minimized.

@shane-tomlinson

shane-tomlinson May 3, 2015
Member

These magic strings should probably live in lib/constants.js

@rfk rfk force-pushed the rfk/signal-auth-type branch from 2975cab to 3c197c3 May 5, 2015
@coveralls
Copy link

@coveralls coveralls commented May 5, 2015

Coverage Status

Coverage decreased (-0.24%) to 97.54% when pulling 3c197c3 on rfk/signal-auth-type into 99ba218 on master.

@shane-tomlinson shane-tomlinson added this to the train 38 milestone May 11, 2015
@shane-tomlinson
Copy link
Member

@shane-tomlinson shane-tomlinson commented May 17, 2015

@rfk - can you rebase this and I can review when ready?

@@ -156,9 +163,12 @@ function (chai, sinon, Session, p, OAuthClient, Assertion, AuthErrors,

return broker.afterResetPasswordConfirmationPoll(account)
.then(function () {
assert.isTrue(broker.finishOAuthFlow.calledWith(account));
assert.isTrue(broker.finishOAuthFlow.calledWith(account, {;

This comment has been minimized.

@pdehaan

pdehaan May 18, 2015
Contributor

What's this little ; doing at the end here?

@shane-tomlinson shane-tomlinson self-assigned this May 18, 2015
@rfk rfk force-pushed the rfk/signal-auth-type branch 2 times, most recently from 9b7dbb0 to 3381470 May 19, 2015
@rfk
Copy link
Member Author

@rfk rfk commented May 19, 2015

OK, rebased and cleaned up a little. I'm not thrilled about this architecturally, it seems to spread the concern across too much of the codebase. But I don't have a better suggestion, since it really is a property of the flow rather than a property of any particular object in the system.

I toyed with putting some sort of "isNewAccount()" indicator on the account object, but it didn't seem to come out any cleaner by the time you figure out how to un-set this flag properly after the first sign-in. At least here the logic is contained to the oauth backends.

@@ -59,14 +68,15 @@ define([
});
},

finishOAuthFlow: function (account) {
finishOAuthFlow: function (account, additionalResultData) {

This comment has been minimized.

@shane-tomlinson

shane-tomlinson May 19, 2015
Member

Maybe instead of only using finishOAuthFlow, there could be two functions finishOAuthSignUp and finishOAuthSignIn. These two functions would each call finishOAuthFlow with the appropriate action.

return self.finishOAuthFlow(account, {
  action: Constants.OAUTH_ACTION_SIGNIN
}).then(function () {

This could be converted to:

return self.finishOAuthSignIn(account)
  .then(function () {

This comment has been minimized.

@rfk

rfk May 20, 2015
Author Member

That is substantially cleaner; nice one @shane-tomlinson!

@@ -19,15 +20,23 @@ define([
return p()
.then(function () {
var redirectTo = result.redirect;
var params = {};

var startOfParams = redirectTo.lastIndexOf('?');

This comment has been minimized.

@shane-tomlinson

shane-tomlinson May 19, 2015
Member

Maybe extract the URL->search params section into lib/url.js? It certainly could be reused in the future, and it'll hopefully reduce the amount of code in this function.

@rfk rfk force-pushed the rfk/signal-auth-type branch from 3381470 to ccf365d May 20, 2015
@rfk rfk force-pushed the rfk/signal-auth-type branch from ccf365d to 6e38ad8 May 20, 2015
@rfk rfk removed the WIP label May 20, 2015
@@ -92,6 +95,18 @@ define([
return p.reject(new Error('subclasses must override sendOAuthResultToRelier'));
},

finishOAuthSignInFlow: function (account, additionalResultData) {
if (! additionalResultData) { additionalResultData = {}; }

This comment has been minimized.

@shane-tomlinson

shane-tomlinson May 20, 2015
Member

This is my lone nit in this PR.

We usually set defaults/missing parameters using this form:

additionalResultData = additionalResultData || {};
@shane-tomlinson
Copy link
Member

@shane-tomlinson shane-tomlinson commented May 20, 2015

I manually merged this in ca3d564. Thanks @rfk!

@shane-tomlinson shane-tomlinson deleted the rfk/signal-auth-type branch Aug 2, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

4 participants