ShieldJS is a TypeScript library for interacting with the Openfort Shield API. It provides easy-to-use methods for retrieving and storing secrets.
- Easy authentication with Openfort and custom authentication options.
- Methods for storing and retrieving secrets securely.
To use ShieldSDK in your project, install it via npm:
npm install @openfort/shield-js
Here's a quick example to get you started:
import { ShieldSDK, ShieldOptions, ShieldAuthOptions } from 'shield-sdk';
const shieldOptions: ShieldOptions = {
apiKey: 'your-api-key',
// Optional: Specify a custom base URL
baseURL: 'https://shield.openfort.xyz'
};
const shieldSDK = new ShieldSDK(shieldOptions);
const authOptions: ShieldAuthOptions = {
// ... authentication options
};
await shieldSDK.storeSecret("your-secret", authOptions);
await shieldSDK.deleteSecret(authOptions);
const secret = await shieldSDK.getSecret(authOptions);
console.log(secret);
storeSecret(secret: string, auth: ShieldAuthOptions): Promise<void>
getSecret(auth: ShieldAuthOptions): Promise<string>
ShieldSDK supports two types of authentication: Openfort and Custom. The type of authentication you use depends on the configuration set in your Shield Dashboard.
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",
}
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",
};