-
Notifications
You must be signed in to change notification settings - Fork 39
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
Add option to manually checking transaction state #27
Conversation
8063ad0
to
a241a1d
Compare
lib/transaction/index.js
Outdated
callback(null, verificationStep); | ||
}); | ||
}; | ||
|
||
transaction.prototype.getAuthVerficationStep = function getAuthVerficationStep() { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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() { |
There was a problem hiding this comment.
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') { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
lib/transaction/index.js
Outdated
throw new errors.UnexpectedInputError('Expected data to be an object'); | ||
} | ||
|
||
if (typeof VALID_METHODS.indexOf(data.method) < 0) { |
There was a problem hiding this comment.
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
lib/transaction/index.js
Outdated
throw new errors.UnexpectedInputError('Expected data to be an object'); | ||
} | ||
|
||
if (typeof VALID_METHODS.indexOf(data.method) < 0) { |
There was a problem hiding this comment.
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() }); |
There was a problem hiding this comment.
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.
lib/transaction/index.js
Outdated
var self = this; | ||
|
||
if (!self.authVerificationStep) { | ||
throw new errors.InvalidStateError('cannot get enrollment confirmation ' + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consistent capitalization -- "Cannot get..."
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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() {};
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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 ?
lib/transaction/index.js
Outdated
callback(null, verificationStep); | ||
}); | ||
}; | ||
|
||
transaction.prototype.getAuthVerficationStep = function getAuthVerficationStep() { |
There was a problem hiding this comment.
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
There was a problem hiding this 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/you/your/
There was a problem hiding this comment.
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 :)
docs/server-side.md
Outdated
```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. |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
lib/errors/invalid_state_error.js
Outdated
} | ||
|
||
InvalidStateError.prototype = object.create(GuardianError.prototype); | ||
InvalidStateError.prototype.contructor = InvalidStateError; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
contructor
...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch
lib/errors/unexpected_input_error.js
Outdated
} | ||
|
||
UnexpectedInputError.prototype = object.create(GuardianError.prototype); | ||
UnexpectedInputError.prototype.contructor = UnexpectedInputError; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
contructor
There was a problem hiding this comment.
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'; |
There was a problem hiding this comment.
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...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch
if (transactionTokenObject.isExpired()) { | ||
asyncHelpers.setImmediate(callback, new errors.CredentialsExpiredError()); | ||
return; | ||
} |
There was a problem hiding this comment.
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; | ||
|
There was a problem hiding this comment.
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
Also