Start typing to search...

Secret

Handles sensitive data used in your Koji app.

Constructor

Instantiates the Secret class.

Parameters

Example

const secret = new KojiBackend.Secret({ res });

Methods

.generateSignedUrl(resource, expireSeconds)

Generates a signed URL for securely serving a file, without exposing the permanent URI. This method provides additional security against sharing or rehosting of protected content.

Parameters

  • resource - String, Full URL of the resource. If the resource is an image hosted on the Koji CDN, you can pass in query parameters to transform it. For example, resize or crop the image.

  • expireSeconds - Number (Optional), Amount of time for which the signed URL remains valid, in seconds. If undefined, signed videos expire after 1 hour, and any other resource expires after 5 minutes.

Returns

Promise<String>, Signed URL for the resource.

Example

const temporaryImagePath = await secret.generateSignedUrl('https://images.koji-cdn.com/e83eaff0-279f-4403-951b-e56507af923d/userData/emfga-icon.png');

// Blur the image
const temporaryBlurredImagePath = await secret.generateSignedUrl('https://images.koji-cdn.com/e83eaff0-279f-4403-951b-e56507af923d/userData/emfga-icon.png?blur=10');

Source: backend/secret/index.ts#L122

.resolveEnvironmentValue(keyPath)

Resolves sensitive data that was stored as an encrypted value on the base project from the Koji Developer Console. This is useful for securely storing things like API keys and other tokens.

Parameters

  • keyPath - String, Encrypted key name.

Returns

Promise<Any>, Decrypted value.

Example

const decryptedValue = await secret.resolveEnvironmentValue('instagram_api_key');

Source: backend/secret/index.ts#L89

.resolveValue(keyPath)

Resolves sensitive data that was {@doclink core-frontend-remix#encryptValue | stored as an encrypted value}.

Parameters

  • keyPath - String, Encrypted key name.

Returns

Promise<Any>, Decrypted value.

Example

const decryptedValue = await secret.resolveValue(encryptedValue);

Source: backend/secret/index.ts#L61

Interfaces

BackendConfigurationInput

Configuration information for the Koji app.

Properties

  • projectId - String (Optional), Unique identifier for the Koji app. Will override data passed through `res`.

  • projectToken - String (Optional), Secret key for the Koji app. Will override data passed through `res`.

  • res - Response (Optional), Express response object. Used in conjunction with middleware to scope environment variables for customized versions of the original Koji app. For the original definition see [[https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/express/index.d.ts#L127 | @types/express]].