rethinkdb / horizon

Horizon is a realtime, open-source backend for JavaScript apps.
MIT License
6.78k stars 351 forks source link

Specify token manually after horizon is connected #812

Open arthurvi opened 8 years ago

arthurvi commented 8 years ago

I work with react native and horizon-react. We use Auth0 as oauth provider. Login happens in a WebView and with some magic I intercept the token from the redirect URL. This token is saved to AsyncStorage and all goes well. But when I intercept the token, I want to let horizon use the new token. The client is already connected with Horizon. I know I can supply my own token and on reboot this works well:

const horizon = new Horizon({
    authType: {
        token: newToken,
        storeLocally: false
    }
});

But is it possible to manually tell horizon to use the new token we intercepted?

Server version: 2 Client version: 2

deontologician commented 8 years ago

Not right now, you need to create a new connection with a token. This is since we authenticate with it, so the first message requires it (the handshake). You could abstract over this with Observables, but it would be annoying since any outstanding queries would get killed.

It's probably a good idea though to allow something like this eventually, like an authenticate message that upgrades a user from anonymous to authenticated, or even allows you to switch between users. I am pretty sure the Horizon backend is set up to allow this kind of handoff (killing outstanding queries you are no longer authorized for)

arthurvi commented 8 years ago

Yes thanks for the response, it would solve the problem with AsyncStorage and react-native and with future platforms that user other kinds of storage mechanisms (Keychain on iOS) for example