Skip to main content

How to Setup the SDK Client

This article explains how to configure an OpenFGA client to call Okta Fine Grained Authorization (FGA).

First make sure that you have:

  1. Created a store and generated your API credentials by following the steps How to get your API keys.
  2. Installed the relevant SDK by following the steps in How To Install The SDK.

Configuration

const { CredentialsMethod, OpenFgaClient } = require('@openfga/sdk'); // OR import { CredentialsMethod, OpenFgaClient } from '@openfga/sdk';

// FGA_API_URL = 'https://api.us1.fga.dev' - Changes based on locality, refer to the ["How to get your API Keys" page](./getting-your-api-keys.mdx)
// FGA_STORE_ID = 'YOUR_STORE_ID' - Get this from your store settings in the dashboard, refer to the ["How to get your API Keys" page](./getting-your-api-keys.mdx)
// FGA_MODEL_ID = 'YOUR_MODEL_ID' - optional, can be overridden per request, helps reduce latency
// FGA_API_TOKEN_ISSUER = 'fga.us.auth0.com'
// FGA_API_AUDIENCE = 'https://api.us1.fga.dev/' - Changes based on locality, refer to the ["How to get your API Keys" page](./getting-your-api-keys.mdx)
// FGA_CLIENT_ID = 'YOUR_CLIENT_ID' - Get this from your store settings in the dashboard, refer to the ["How to get your API Keys" page](./getting-your-api-keys.mdx)
// FGA_CLIENT_SECRET = 'YOUR_CLIENT_SECRET' - Get this from your store settings in the dashboard, refer to the ["How to get your API Keys" page](./getting-your-api-keys.mdx)

const openFga = new OpenFgaClient({
apiUrl: process.env.FGA_API_URL,
storeId: process.env.FGA_STORE_ID,
authorizationModelId: process.env.FGA_MODEL_ID,
credentials: {
method: CredentialsMethod.ClientCredentials,
config: {
apiTokenIssuer: process.env.FGA_API_TOKEN_ISSUER,
apiAudience: process.env.FGA_API_AUDIENCE,
clientId: process.env.FGA_CLIENT_ID,
clientSecret: process.env.FGA_CLIENT_SECRET,
},
}
});

Have Feedback?

You can use any of our support channels for any questions or suggestions you may have.