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

Clear local state when checkSession call fails #758

Merged
merged 2 commits into from
May 23, 2018

Conversation

luisrudge
Copy link
Contributor

partial fix for #402

}
var parsedHash = eventData.event.data.response;
_this.webAuth.validateAuthenticationResponse(options, parsedHash, cb);
_this.webAuth.transactionManager.clearTransaction(error.state);
Copy link
Contributor

Choose a reason for hiding this comment

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

OK. This is the goal of this PR. However this clearTransaction won't get called if error!=null (see line 66, happy path). Is that fine?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, because then we'll call validateAuthenticationResponse, which needs the transaction to work (and it will be removed later)

@@ -58,22 +59,22 @@ WebMessageHandler.prototype.run = function(options, cb) {
) {
var error = err;
Copy link
Contributor

Choose a reason for hiding this comment

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

this could be

var error = err ? err : eventData.event.data.response.error
if (!error) {
  parsedHash =..
  return validateAuthenticationResponse(...);
}

//continue handling errors

Copy link
Contributor Author

Choose a reason for hiding this comment

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

see error = eventData.event.data.response;the eventData.event.data.response.error property is a string.

@@ -2402,7 +2404,7 @@ describe('auth0.WebAuth', function() {
stub(IframeHandler.prototype, 'init', function() {
this.timeoutCallback();
});
this.auth0.checkSession({}, function(err, data) {
this.auth0.checkSession({ state: 'foobar' }, function(err, data) {
Copy link
Contributor

Choose a reason for hiding this comment

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

why has this changed? If I read the tests below (line 2452) it seems it's using this key as default state key value to remove when no error is provided (because of timeout). What would happen if this value is not given, like in the previous diff, when an error is also not provided (because of timeout)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because the underlying code now depends on a state and my stub for the transactionManager.process method doesn't return a state:

return Object.assign({}, params, { from: 'transaction-manager' });

Since I already tested (elsewhere)[https://github.com/auth0/auth0.js/blob/6ac59c4faedc003820f3909aef5b5d57a572fad7/test/web-auth/web-auth.test.js#L2362] that we handle those params correctly, there's no need to stub the method again, so I just added the state

@@ -22,7 +22,8 @@ function runWebMessageFlow(authorizeUrl, options, callback) {
timeoutCallback: function() {
callback({
error: 'timeout',
error_description: 'Timeout during executing web_message communication'
error_description: 'Timeout during executing web_message communication',
state: options.state
Copy link
Contributor

Choose a reason for hiding this comment

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

I find odd having an error object having "extra values" just for the sake of your code simplicity. It's easy to forget to filter the attributes returned to the user later.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the server also sends the same object {error, error_description, state}. I'm just replicating what the server does

@lbalmaceda lbalmaceda self-requested a review May 23, 2018 19:54
Copy link
Contributor

@lbalmaceda lbalmaceda left a comment

Choose a reason for hiding this comment

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

🍻

@luisrudge luisrudge merged commit 5a1fddb into master May 23, 2018
@luisrudge luisrudge deleted the fix-clear-localstate-when-checksession-fails branch May 23, 2018 20:40
@luisrudge luisrudge added this to the v9.6.0 milestone May 28, 2018
bors bot referenced this pull request in mozilla/delivery-console May 28, 2018
170: Update dependency auth0-js to v9.6.0 r=rehandalal a=renovate[bot]

This Pull Request updates dependency [auth0-js](https://github.com/auth0/auth0.js) from `v9.5.1` to `v9.6.0`



<details>
<summary>Release Notes</summary>

### [`v9.6.0`](https://github.com/auth0/auth0.js/blob/master/CHANGELOG.md#v960httpsgithubcomauth0auth0jstreev960-2018-05-28)
[Compare Source](auth0/auth0.js@v9.5.1...v9.6.0)
[Full Changelog](auth0/auth0.js@v9.5.1...v9.6.0)

**Changed**
- Added `access_type` and `display` to the parameters-whitelist [\#&#8203;760](`https://github.com/auth0/auth0.js/pull/760`) ([lordnox])

**Fixed**
- Clear local state when checkSession call fails [\#&#8203;758](`https://github.com/auth0/auth0.js/pull/758`) ([luisrudge])

---

</details>




---

This PR has been generated by [Renovate Bot](https://renovatebot.com).

Co-authored-by: Renovate Bot <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants