Page MenuHomePhabricator

[lib] Tunnelbroker support for unauthorized sessions
ClosedPublic

Authored by bartek on Jan 26 2024, 6:08 AM.
Tags
None
Referenced Files
Unknown Object (File)
Tue, Jul 2, 1:05 AM
Unknown Object (File)
Sun, Jun 30, 6:52 PM
Unknown Object (File)
Sun, Jun 30, 1:07 PM
Unknown Object (File)
Sun, Jun 30, 12:21 PM
Unknown Object (File)
Sun, Jun 30, 1:50 AM
Unknown Object (File)
Sat, Jun 29, 7:40 AM
Unknown Object (File)
Sat, Jun 29, 7:40 AM
Unknown Object (File)
Sat, Jun 29, 7:40 AM
Subscribers

Details

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,
]);

Diff Detail

Repository
rCOMM Comm
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

bartek held this revision as a draft.
bartek published this revision for review.Jan 26 2024, 8:25 AM
lib/types/tunnelbroker/session-types.js
8 ↗(On Diff #36159)

Can we name this TunnelbrokerDeviceTypes? There's also IdentityDeviceTypes and just DeviceTypes

49 ↗(On Diff #36159)

This doesn't match up with the Flow types (capitalization)

kamil added inline comments.
lib/tunnelbroker/tunnelbroker-context.js
184 ↗(On Diff #36159)

we use this convention in this file (I copied it from lib/socket.react.js)

lib/types/tunnelbroker/session-types.js
40 ↗(On Diff #36159)

that's my mistake from D9596 - could you quickfix this?

This revision is now accepted and ready to land.Jan 29 2024, 3:28 AM

Apply requested quickfixes