horizon icon indicating copy to clipboard operation
horizon copied to clipboard

Specify token manually after horizon is connected

Open arthurvi opened this issue 7 years ago • 2 comments

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

arthurvi avatar Sep 06 '16 10:09 arthurvi

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)

deontologician avatar Sep 09 '16 02:09 deontologician

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

arthurvi avatar Sep 09 '16 07:09 arthurvi