@openfort/shield-js
v0.1.13
Published
[![Version](https://img.shields.io/npm/v/@openfort/shield-js.svg)](https://www.npmjs.org/package/@openfort/shield-js)
Downloads
1,989
Readme
ShieldJS
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",
};