[lib] Tunnelbroker support for unauthorized sessions
Summary:
Add support for clients to start unauthorized Tunnelbroker sessions. They're initialized by calling setUnauthorizedDeviceID() with a non-null value.
Test Plan:
Test plan for D10829 was repeated for this diff, with the following test snippet (modified native/qr-code-screen.js):
const [deviceID, setDeviceID] = React.useState<?string>(); const { setUnauthorizedDeviceID } =useTunnelbroker(); const dispatch = useDispatch(); React.useEffect(() => { if (!deviceID) { return; } // 1. instantly start unauthorized session setUnauthorizedDeviceID(deviceID); console.log('SECONDARY DEVICE: setUseAnonymousSession', deviceID); // 2. after 5s fake login (switch to authorized session) setTimeout(async () => { console.log('SECONDARY DEVICE: faking login'); await commCoreModule.setCommServicesAuthMetadata( 'user', deviceID || 'foo', '123', ); dispatch({ type: setAccessTokenActionType, payload: '123' }); setUnauthorizedDeviceID(null); }, 5000); // 3. after 10s fake logout (don't switch to unauthorized session => disconnect) setTimeout(async () => { console.log('SECONDARY DEVICE: faking logout'); await commCoreModule.setCommServicesAuthMetadata('', '', ''); dispatch({ type: setAccessTokenActionType, payload: null }); setUnauthorizedDeviceID(null); }, 10000); return () => { setUnauthorizedDeviceID(null); }; }, [ setUnauthorizedDeviceID, deviceID, dispatch, ]);
Reviewers: kamil
Reviewed By: kamil
Subscribers: ashoat, tomek
Differential Revision: https://phab.comm.dev/D10832