HomePhabricator
Diffusion Comm 0a577e6b0879

[lib] Tunnelbroker support for unauthorized sessions

Description

[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.

Depends on D10829, D10782

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

Details

Provenance
bartekAuthored on Jan 26 2024, 5:29 AM
Reviewer
kamil
Differential Revision
D10832: [lib] Tunnelbroker support for unauthorized sessions
Parents
rCOMM33f2b7fa09e3: [lib] Reset Tunnelbroker connection when credentials change
Branches
Unknown
Tags
Unknown