0.1.13 • Published 9 months ago

@openfort/shield-js v0.1.13

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

ShieldJS

Version

ShieldJS is a TypeScript library for interacting with the Openfort Shield API. It provides easy-to-use methods for retrieving and storing secrets.

Features

  • Easy authentication with Openfort and custom authentication options.
  • Methods for storing and retrieving secrets securely.

Installation

To use ShieldSDK in your project, install it via npm:

npm install @openfort/shield-js

Usage

Here's a quick example to get you started:

Importing the SDK

import { ShieldSDK, ShieldOptions, ShieldAuthOptions } from 'shield-sdk';

Initializing the SDK

const shieldOptions: ShieldOptions = {
apiKey: 'your-api-key',
// Optional: Specify a custom base URL
baseURL: 'https://shield.openfort.xyz'
};

const shieldSDK = new ShieldSDK(shieldOptions);

Storing a Secret

const authOptions: ShieldAuthOptions = {
// ... authentication options
};

await shieldSDK.storeSecret("your-secret", authOptions);

Deleting a Secret

await shieldSDK.deleteSecret(authOptions);

Retrieving a Secret

const secret = await shieldSDK.getSecret(authOptions);
console.log(secret);

API Reference

  • storeSecret(secret: string, auth: ShieldAuthOptions): Promise<void>
  • getSecret(auth: ShieldAuthOptions): Promise<string>

Authentication

ShieldSDK supports two types of authentication: Openfort and Custom. The type of authentication you use depends on the configuration set in your Shield Dashboard.

Openfort Authentication

When you configure your Shield Dashboard to use Openfort, you should use OpenfortAuthOptions for authentication. Depending on your setup, the way you use OpenfortAuthOptions can vary:

  • Using an Openfort Token: If you are using a token generated by Openfort, simply provide the token in openfortOAuthToken.
const authOptions: OpenfortAuthOptions = {
    openfortOAuthToken: "your-openfort-token",
};
  • Using Third-Party OAuth Tokens: If you are using a third-party authentication provider, you need to provide the identity token, the provider type, and the token type:
const authOptions: OpenfortAuthOptions = {
    openfortOAuthToken: "your-identity-token",
    openfortOAuthProvider: OpenfortOAuthProvider.FIREBASE,
    openfortOAuthTokenType: OpenfortOAuthTokenType.ID_TOKEN
};

The Provider and Token Type enums are defined as follows:

export enum OpenfortOAuthProvider {
    ACCELBYTE = "accelbyte",
    FIREBASE = "firebase",
    LOOTLOCKER = "lootlocker",
    PLAYFAB = "playfab",
    CUSTOM = "custom",
    OIDC = "oidc",
}

export enum OpenfortOAuthTokenType {
    ID_TOKEN = "idToken",
    CUSTOM_TOKEN = "customToken",
}

Custom Authentication

If your Shield Dashboard is configured for Custom Authentication, use CustomAuthOptions. You will need to provide your custom token in the customToken field.

const authOptions: CustomAuthOptions = {
    customToken: "your-custom-token",
};
0.1.13

9 months ago

0.1.11

10 months ago

0.1.10

12 months ago

0.1.8

1 year ago

0.1.9

12 months ago

0.1.7

1 year ago

0.1.6

1 year ago

0.1.4

1 year ago

0.1.5

1 year ago

0.1.3

1 year ago

0.1.2

1 year ago

0.1.1

1 year ago

0.0.10

1 year ago

0.0.11

1 year ago

0.1.0

1 year ago

0.0.9

1 year ago

0.0.8

1 year ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.7

1 year ago

0.0.6

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago