Skip to content
This repository has been archived by the owner on Apr 23, 2019. It is now read-only.

Socket reconnect upgrade auth #3

Merged
merged 6 commits into from
Nov 21, 2016
Merged

Conversation

marshallswain
Copy link
Member

The client needs to authenticate upon reconnect or transport upgrade.
Related to feathersjs-ecosystem/authentication#272

I can't figure out how to test the upgrade message. Can't even get basic socket communication to work. What am I doing wrong?

marshallswain and others added 3 commits October 25, 2016 09:36
This adds a `getSocketMethodName` and moves the `method` variable up a level in the authenticate method, so that sockets can be authenticated inside the `handleResponse` callback.  `handleResponse` is probably the best place for this because we only want it to happen after successful auth.
but I can’t even get this simple socket communication to work.  What am I doing wrong?
@@ -132,4 +132,14 @@ describe('Socket.io client authentication', () => {
});
});
});

it.only('handles upgrade events', done => {
Copy link
Member

Choose a reason for hiding this comment

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

@marshallswain @daffl do you know how to simulate upgrade events? I can't get this test to pass either but I don't think it is actually testing upgrade functionality anyway.

Copy link
Member Author

Choose a reason for hiding this comment

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

Nope. I couldn't figure it out.

@ekryski
Copy link
Member

ekryski commented Nov 21, 2016

@feathersjs/core-team ready for review.

Because I was fighting context issues I've moved all the utils to the Passport class. I managed to get sockets to re-authenticate automatically. As result you can now check if the socket is authenticated on the client side by looking at socket.authenticated.

In the event that your access token expires while you are disconnected from the server the automatic re-authentication will fail. Since we are using promises to keep the API clean that error would be swallowed. So I've now introduced 2 events you can listen for on the client.

  • app.on('upgrade-auth-error', error => {}), for when auth during an upgrade fails, and
  • app.on('reconnect-auth-error', error => {}), for when auth during a reconnect fails

@daffl
Copy link
Member

daffl commented Nov 21, 2016

Wouldn't a single auth-error or authentication-error event be enough?

@ekryski
Copy link
Member

ekryski commented Nov 21, 2016

@daffl I thought about it but when talking to @corymsmith we thought it might be confusing for people because these are special case auth errors and if it was just called auth-error they might not call .catch() on authenticate() (which is the normal flow).

These really are edge cases for when your access token becomes invalid when disconnected or your server has a bug in the authentication flow that causes it to continually error.

I've added docs to readme about usage.

If you can come up with a decent name I'm open to consolidating so you don't need to register 2 listeners. I was thinking maybe re-authentication-error or auto-auth-error. What do you think?

passport = new Passport(app, options);
});

describe.skip('getJWT', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Are these tests still supposed to be skipped?

Copy link
Member

Choose a reason for hiding this comment

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

Yes and no. I was being lazy because they need different setup and teardown now that they are part of the Passport class. That whole class needs more unit tests but I figured I would come back to them.

Copy link
Contributor

Choose a reason for hiding this comment

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

Gotcha, all good, was more curious if you accidentally left the .skip in there

@corymsmith
Copy link
Contributor

At first glance this all looks good to me, I think maybe we can consolidate those 2 events into one as you suggested, maybe reauthentication-error?

@ekryski
Copy link
Member

ekryski commented Nov 21, 2016

@corymsmith @daffl consolidated the events now so it is just @corymsmith suggested.

@corymsmith
Copy link
Contributor

I say 🚢 this bad boy

@ekryski ekryski merged commit 35eb500 into master Nov 21, 2016
@ekryski ekryski deleted the socket-reconnect-upgrade-auth branch November 21, 2016 02:09
@ekryski
Copy link
Member

ekryski commented Nov 21, 2016

released as v0.1.1

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants