Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to manually checking transaction state #27

Merged
merged 16 commits into from
Mar 7, 2017

Conversation

dafortune
Copy link
Contributor

Also

  • Serialize enrollment and verification step
  • Add option to get the step

@dafortune dafortune force-pushed the allow-manual-transaction-checking branch from 8063ad0 to a241a1d Compare March 3, 2017 04:02
callback(null, verificationStep);
});
};

transaction.prototype.getAuthVerficationStep = function getAuthVerficationStep() {
Copy link
Contributor Author

@dafortune dafortune Mar 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be easily converted in @nikolaseu proposal of adding the method verifyAuth to the transaction, just call getAuthVerficationStep().verify(...) on that method.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo in "getAuthVerficationStep()", missing "i" in verification

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

return self.authVerificationStep;
};

transaction.prototype.getEnrollmentConfirmationStep = function getEnrollmentConfirmationStep() {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be easily converted in @nikolaseu proposal of adding the method confirmEnrollment to the transaction, just call getEnrollmentConfirmationStep().confirm(...) on that method.

@@ -13,6 +14,8 @@ exports.create = function create(options) {

if (transport === 'polling') {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to replace this by @thoper proposed name.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We support both, internally I keep using transport not to spread the changes.

throw new errors.UnexpectedInputError('Expected data to be an object');
}

if (typeof VALID_METHODS.indexOf(data.method) < 0) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add test for invalid method in the serialized transaction

throw new errors.UnexpectedInputError('Expected data to be an object');
}

if (typeof VALID_METHODS.indexOf(data.method) < 0) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add test for invalid method in the serialized transaction

@@ -44,7 +55,10 @@ enrollmentConfirmationStep.prototype.confirm = function confirm(data) {
};

var confirmTask = function confirmTask(done) {
self.strategy.confirm(data, done);
self.strategy.confirm(data, function confirmationDataAccepted(err, result) {
acceptedCallback(err, { recoveryCode: self.enrollmentAttempt.getRecoveryCode() });
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

passing the recovery code here don't quite convince me, but, how are you going to get the recovery code otherwise... making self.enrollmentAttempt.getRecoveryCode() public seems like opening the door too much considering that we are going to change how enrollmentAttempt works.

var self = this;

if (!self.authVerificationStep) {
throw new errors.InvalidStateError('cannot get enrollment confirmation ' +
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consistent capitalization -- "Cannot get..."

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@@ -57,14 +67,27 @@ authVerificationStep.prototype.verify = function verify(data) {
verificationPayload = verificationPayload || {};

if (err) {
if (acceptedCallback) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can this ever be false? I see this before

acceptedCallback = acceptedCallback || function noop() {};

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point forgot to remove that

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

// accepted by the service provider, on the other hand
// we still need to wait for (loginOrRejectTask) to trigger the event.
// loginOrRejectTask might never be triggered in case of transport=manual
acceptedCallback(null, payload);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like this actually needs to be always there, so the previous if is not required ?

callback(null, verificationStep);
});
};

transaction.prototype.getAuthVerficationStep = function getAuthVerficationStep() {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo in "getAuthVerficationStep()", missing "i" in verification

Copy link

@fiddur fiddur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it could be good to put the examples in some example-dir and run them in a test (mocking all external calls), if it's not too much work. Broken examples is a really bad thing.


```js
// WARNING 1: This is an advanced example, before using it consider if the
// hosted-page option does not match you use case, they are easier to implement
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/you/your/

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is your environment not yours enrollment. Good catch :)

```js
// WARNING 1: This is an advanced example, before using it consider if the
// hosted-page option does not match you use case, they are easier to implement
// and better suitted for most use cases.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/suitted/suited/

// WARNING 2: POST Methods require CSRF protection, don't forget to add them or
// you will be at risk of CSRF attacks, this example left them out for simplicity
// reasons and because there are many different ways to add them that
// are really specific to your enrollment.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this warning is superfluous; the default for a browser is to block XHR posts to other domains, so anyone adding a header for allowed origins do so at their own risk.

Copy link
Contributor Author

@dafortune dafortune Mar 7, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if the warning is superfluos: cors is not necessary to do csrf, adding a form that triggers itself is enough (assuming there is a body parser that allows it), in this case the attack is quite difficult because you can trigger only one call, but some attackers tend to be smart and I think it is better to close as many doors as posible, even if they are not easy to exploit.

}

InvalidStateError.prototype = object.create(GuardianError.prototype);
InvalidStateError.prototype.contructor = InvalidStateError;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

contructor...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch

}

UnexpectedInputError.prototype = object.create(GuardianError.prototype);
UnexpectedInputError.prototype.contructor = UnexpectedInputError;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

contructor

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch

lib/index.js Outdated
@@ -44,7 +53,7 @@ function auth0GuardianJS(options) {
self.httpClient = object.get(options, 'dependencies.httpClient',
httpClient(self.serviceUrl, globalTrackingId));

self.transport = options.transport || 'socket';
self.transport = options.transport || options.state_checking_mechanism || 'socket';
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The jsdoc says stateCheckingMechanism; I don't see anything convering it to snake_case...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch

@dafortune
Copy link
Contributor Author

@dafortune
Copy link
Contributor Author

#28

if (transactionTokenObject.isExpired()) {
asyncHelpers.setImmediate(callback, new errors.CredentialsExpiredError());
return;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<3

? self.authVerificationStep.serialize() : null;
data.enrollmentConfirmationStep = self.enrollmentConfirmationStep
? self.enrollmentConfirmationStep.serialize() : null;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move 236, to:

data.enrollmentAttempt: this.enrollmentAttempt ? this.enrollmentAttempt.serialize() : undefined

@dafortune dafortune merged commit 42e9dcc into auth0:master Mar 7, 2017
@dafortune dafortune deleted the allow-manual-transaction-checking branch March 7, 2017 22:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants