Running Your FGA Application

Using the SDK

Download the SDK

npm install @frontegg/authz-client
yarn add @frontegg/authz-client

Now that everything is set up, you can test if a hero can rent an HQ:

// server.ts
// ...

import {AuthZOpaClient} from '@frontegg/authz-client'

// ...
const client = new AuthZOpaClient({ url: 'http://localhost:8181' });
const authz = await client.authorized(context.tenantId, {
  scope: 'Rent',
  subjectContext: { id: heroId },
  assetContext: { id: assetId }
// ...

Let's try running the example server:

npm server:local
yarn start:local

Now let's see if Batman can Rent the Fortress of solitude

curl --request POST \
  --url http://localhost:3000/ \
  --header 'Content-Type: application/json' \
  --data '{
	"tenantId": "tenant-id",
	"heroId": "batman-hero-id",
	"assetId": "fortress-of-solitude-id"

// Response: { message: "Hero batman-id can't rent asset fortress-of-solitude-id", reasons: ["superman-rent"] }

What’s Next