defender-sdk icon indicating copy to clipboard operation
defender-sdk copied to clipboard

Add support authentication credentials caching

Open MCarlomagno opened this issue 1 year ago • 3 comments

Description

Added support to authenticate using apiKey + accessToken (instead of apiSecret). This feature is supported in relay signer package only, but extendable to other packages too.

How it works

Now we expose getApiKey() & getAccessToken() functions, these credentials can be reused in other Defender SDK instances. This process skips authentication endpoints but devs must setup their own refresh process or the client will throw Unauthorized after the token was expired ⚠️

Example

  const creds = {
    relayerApiKey: process.env.RELAYER_API_KEY,
    relayerApiSecret: process.env.RELAYER_API_SECRET,
  };
  const client = new Defender(creds);

  const relayerApiKey = client.relaySigner.getApiKey();
  const accessToken = await client.relaySigner.getAccessToken();
  const cachedSession = { relayerApiKey, accessToken };
  
  ...  

  // Another Defender instance running in any other environment
  const client = new Defender(cachedSession);
  const info = await client.relaySigner.getRelayerStatus();

MCarlomagno avatar May 22 '24 09:05 MCarlomagno

⚠️ No Changeset found

Latest commit: d5a26c9f7343bf492efa9b5767a34d206dd14623

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

changeset-bot[bot] avatar May 22 '24 09:05 changeset-bot[bot]

New dependencies detected. Learn more about Socket for GitHub ↗︎

Package New capabilities Transitives Size Publisher
npm/@openzeppelin/[email protected] Transitive: environment, filesystem +10 903 kB collins-oz

View full report↗︎

socket-security[bot] avatar May 22 '24 09:05 socket-security[bot]

Should we still need this, may be it's better to keep this branch and close the pr and revisit it later now that we have auth caching being done on the BE

tirumerla avatar Jul 12 '24 17:07 tirumerla