Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

APP-2520: Update typescript sdk to work with api keys #164

Merged
merged 1 commit into from
Sep 20, 2023

Conversation

jr22
Copy link
Member

@jr22 jr22 commented Sep 15, 2023

Ticket: https://viam.atlassian.net/browse/APP-2520

Updated the dial code to support API keys. Here is a code sample for how connecting with api keys works:

async function connect(): Promise<VIAM.RobotClient> {
  // You can remove this block entirely if your robot is not authenticated.
  // Otherwise, replace with an actual secret.
  const credential = {
    payload: "<API-KEY>",
    type: 'api-key',
  };

  // Replace with the host of your actual robot running Viam.
  const host = '<HOST>';

  // Replace with the signaling address. If you are running your robot on Viam,
  // it is most likely https://app.viam.com:443.
  const signalingAddress = '<SIGNALING_ADDRESS>';

  // You can replace this with a different ICE server, append additional ICE
  // servers, or omit entirely. This option is not strictly required but can
  // make it easier to connect via WebRTC.
  const iceServers = [{ urls: 'stun:global.stun.twilio.com:3478' }];

  return VIAM.createRobotClient({
    host,
    credential,
    authEntity: "<API-KEY-ID>",
    signalingAddress,
    iceServers,
    // optional: configure reconnection options
    reconnectMaxAttempts: 7,
    reconnectMaxWait: 1000,
  });
}

The biggest difference here is that the authEntity is actually the api key ID and not the host. I updated the code to conditionally use authEntity to connect if it exists and fall back on the old behavior of impliedURL otherwise. I manually tested that this works for both location secrets and API keys (although we are planning to deprecate secrets soon).

Heres the scope and spec that describes the changes for org api keys. We had to make similar changes to the python, c++ and rust SDKs.

Let me know if there any tests I should update! Also happy to chat offline if you want more details.

Copy link
Contributor

@maximpertsov maximpertsov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should also add the same logic for direct gRPC connections (here)

You can test this by running same script you ran but omitting signalingAddress and iceServers from the options provided to createRobotClient:

  return VIAM.createRobotClient({
    host,
    credential,
    authEntity: "<API-KEY-ID>",
    // optional: configure reconnection options
    reconnectMaxAttempts: 7,
    reconnectMaxWait: 1000,
  });

@jr22
Copy link
Member Author

jr22 commented Sep 20, 2023

TL;DR on our conversation from this morning:

  • dialDirect works out of the box since it is already passing conf.authEntity to the connection
  • it doesn't work right now though because it relies on the work being done in APP-2591. I did manually hack in those changes though to make sure that dialDirect will work once they're in.
  • i also found a bug for dialDirect that I filed here RSDK-5032

thanks for all your help on this!

@jr22 jr22 merged commit e9f79da into viamrobotics:main Sep 20, 2023
2 checks passed
@jr22 jr22 deleted the APP-2520 branch September 20, 2023 14:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants