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

Add support authentication credentials caching #359

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

MCarlomagno
Copy link
Member

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 MCarlomagno requested a review from zeljkoX May 22, 2024 09:28
Copy link

changeset-bot bot commented May 22, 2024

⚠️ No Changeset found

Latest commit: d5a26c9

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

@MCarlomagno MCarlomagno requested a review from tirumerla May 22, 2024 09:28
Copy link

socket-security bot commented May 22, 2024

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

Package New capabilities Transitives Size Publisher
npm/@openzeppelin/defender-sdk@1.13.1 Transitive: environment, filesystem +10 903 kB collins-oz

View full report↗︎

@tirumerla
Copy link
Collaborator

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

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