Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Commit

Permalink
release(v0.10.0): OpenFGA SDK wrapper and deprecate
Browse files Browse the repository at this point in the history
  • Loading branch information
rhamzeh committed Feb 21, 2024
1 parent 8d4473d commit a121bb6
Show file tree
Hide file tree
Showing 26 changed files with 2,701 additions and 2,536 deletions.
18 changes: 18 additions & 0 deletions .github/dependabot.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
version: 2
updates:
- package-ecosystem: "npm"
directory: "/"
schedule:
interval: "weekly"
groups:
dependencies:
patterns:
- "*"
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
groups:
dependencies:
patterns:
- "*"
75 changes: 29 additions & 46 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
@@ -1,57 +1,29 @@
name: Build, Test and Publish

on:
merge_group:
push:
pull_request:
workflow_dispatch:

jobs:
fossa:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up node
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
registry-url: 'https://registry.npmjs.org'
scope: '@auth0'
always-auth: false
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Run FOSSA scan and upload build data
uses: fossas/fossa-action@main
with:
api-key: ${{ secrets.FOSSA_API_KEY }}
branch: ${{ github.ref_name }}
- name: Run FOSSA tests
uses: fossas/fossa-action@main
with:
api-key: ${{ secrets.FOSSA_API_KEY }}
run-tests: true

snyk:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Run Snyk to check for vulnerabilities
uses: snyk/actions/node@master
env:
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
permissions:
contents: read

jobs:
build:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [14.x, 16.x, 18.x]
node-version: [14.x, 16.x, 18.x, 20.x]

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
fetch-depth: 0

- name: Set up node
uses: actions/setup-node@v3
uses: actions/setup-node@8f152de45cc393bb48ce5d89d36b731f54556e65 # v4.0.0
with:
node-version: ${{ matrix.node-version }}
registry-url: 'https://registry.npmjs.org'
Expand All @@ -69,12 +41,14 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
fetch-depth: 0

- name: Set up node
uses: actions/setup-node@v3
uses: actions/setup-node@8f152de45cc393bb48ce5d89d36b731f54556e65 # v4.0.0
with:
node-version: '18'
node-version: '20'
cache: 'npm'

- name: Install dependencies
Expand All @@ -92,15 +66,20 @@ jobs:
publish:
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/v')
needs: [build, test, fossa, snyk]
needs: [build, test]
permissions:
contents: read
id-token: write

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
fetch-depth: 0

- name: Set up node
uses: actions/setup-node@v3
uses: actions/setup-node@8f152de45cc393bb48ce5d89d36b731f54556e65 # v4.0.0
with:
node-version: '18'
node-version: '20'
registry-url: 'https://registry.npmjs.org'
scope: '@auth0'
always-auth: false
Expand All @@ -118,11 +97,15 @@ jobs:
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/v')
needs: publish
permissions:
contents: write

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
fetch-depth: 0

- uses: Roang-zero1/github-create-release-action@5cf058ddffa6fa04e5cda07c98570c757dc4a0e1
- uses: Roang-zero1/github-create-release-action@57eb9bdce7a964e48788b9e78b5ac766cb684803 # v3.0.1
with:
version_regex: ^v[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+
env:
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/semgrep.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ jobs:
image: returntocorp/semgrep
if: (github.actor != 'dependabot[bot]' && github.actor != 'snyk-bot')
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
fetch-depth: 0
- run: semgrep ci
env:
SEMGREP_APP_TOKEN: ${{ secrets.SEMGREP_APP_TOKEN }}
1 change: 0 additions & 1 deletion .openapi-generator-ignore

This file was deleted.

32 changes: 0 additions & 32 deletions .openapi-generator/FILES

This file was deleted.

1 change: 0 additions & 1 deletion .openapi-generator/VERSION

This file was deleted.

7 changes: 7 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"singleQuote": false,
"trailingComma": "all",
"tabWidth": 2,
"bracketSpacing": true,
"printWidth": 120
}
39 changes: 39 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,44 @@
# Changelog

## v0.10.0

### [0.10.0](https://github.com/auth0-lab/fga-js-sdk/compare/v0.9.1...v0.10.0) (2023-12-23)

[Breaking]

Changed:
- `Auth0FgaApi` and `Auth0FgaClient` are now just simple wrappers on top of `OpenFgaFgaApi` and `OpenFgaFgaClient`

Chore:
- chore(ci): enable dependabot
- chore(deps): update dependencies

Note: As of this point this SDK is no longer auto-generated and is instead just a simple wrapper on top of [@openfga/sdk](https://github.com/openfga/js-sdk)

For the time being, we have decided to deprecate the `@auth0/fga` SDK as it duplicates the functionality of `@openfga/sdk`.

We strongly recommend you use the `@openfga/sdk` directly instead with the following configuration:

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

const fgaClient = new OpenFgaClient({
apiScheme: "https",
apiHost: "api.us1.fga.dev",
storeId: process.env.FGA_STORE_ID,
authorizationModelId: process.env.FGA_MODEL_ID,
credentials: { // Credentials are not needed if connecting to the Playground API
method: CredentialsMethod.ClientCredentials,
config: {
apiTokenIssuer: "fga.us.auth0.com",
apiAudience: "https://api.us1.fga.dev/",
clientId: process.env.FGA_CLIENT_ID,
clientSecret: process.env.FGA_CLIENT_SECRET,
},
}
});
```

## v0.9.1

### [0.9.1](https://github.com/auth0-lab/fga-js-sdk/compare/v0.9.0...v0.9.1) (2023-01-23)
Expand Down
39 changes: 18 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
# JavaScript and Node.js SDK for Auth0 Fine Grained Authorization (FGA)
# JavaScript and Node.js SDK for Okta Fine Grained Authorization (FGA)

[![npm](https://img.shields.io/npm/v/@auth0/fga.svg?style=flat)](https://www.npmjs.com/package/@auth0/fga)
[![Release](https://img.shields.io/github/v/release/auth0-lab/fga-js-sdk?sort=semver&color=green)](https://github.com/auth0-lab/fga-js-sdk/releases)
[![License](https://img.shields.io/badge/License-MIT-blue.svg)](./LICENSE)
[![FOSSA Status](https://app.fossa.com/api/projects/custom%2B4989%2Fgithub.com%2Fauth0-lab%2Ffga-js-sdk.svg?type=shield)](https://app.fossa.com/api/projects/custom%2B4989%2Fgithub.com%2Fauth0-lab%2Ffga-js-sdk.svg?type=shield)
[![Discord Server](https://img.shields.io/discord/759188666072825867?color=7289da&logo=discord "Discord Server")](https://discord.com/channels/759188666072825867/930524706854031421)
[![Twitter](https://img.shields.io/twitter/follow/Auth0Lab?color=%23179CF0&logo=twitter&style=flat-square "@Auth0Lab on Twitter")](https://twitter.com/Auth0Lab)

This is an autogenerated JavaScript SDK for Auth0 Fine Grained Authorization (FGA). It provides a wrapper around the [Auth0 Fine Grained Authorization API](https://docs.fga.dev/api/service), and includes TS typings.

Expand Down Expand Up @@ -71,7 +70,6 @@ const fgaClient = new OpenFgaClient({

- [Auth0 Fine Grained Authorization (FGA) Documentation](https://docs.fga.dev)
- [Auth0 Fine Grained Authorization (FGA) API Documentation](https://docs.fga.dev/api/service)
- [Twitter](https://twitter.com/Auth0Lab)
- [Auth0 Fine Grained Authorization (FGA) Discord Community](https://discord.gg/8naAwJfWN6)
- [Zanzibar Academy](https://zanzibar.academy)
- [Google's Zanzibar Paper (2019)](https://research.google/pubs/pub48190/)
Expand All @@ -95,23 +93,22 @@ yarn add @auth0/fga
### Initializing the API Client

```javascript
const { Auth0FgaApi } = require('@auth0/fga'); // OR import { Auth0FgaApi } from '@auth0/fga';
const { OktaFgaClient } = require('@auth0/fga'); // OR import { Auth0FgaApi } from '@auth0/fga';

// See https://github.com/auth0-lab/fga-js-sdk#getting-your-store-id-client-id-and-client-secret
const auth0Fga = new Auth0FgaApi({
environment: AUTH0_FGA_ENVIRONMENT, // can be: "us"/"staging"/"playground"
storeId: AUTH0_FGA_STORE_ID,
clientId: AUTH0_FGA_CLIENT_ID, // Required for all environments except playground
clientSecret: AUTH0_FGA_CLIENT_SECRET, // Required for all environments except playground
const fgaClient = new OktaFgaClient({
environment: AUTH0_FGA_ENVIRONMENT, // can be: "us1"/"staging"/"playground"
storeId: FGA_STORE_ID,
clientId: FGA_CLIENT_ID, // Required for all environments except playground
clientSecret: FGA_CLIENT_SECRET, // Required for all environments except playground
});
```


### Getting your Store ID, Client ID and Client Secret

#### Production

Make sure you have created your credentials on the Auth0 FGA Dashboard. [Learn how ➡](https://docs.fga.dev/intro/dashboard#create-api-credentials)
Make sure you have created your credentials on the Okta FGA Dashboard. [Learn how ➡](https://docs.fga.dev/intro/dashboard#create-api-credentials)

You will need to set the `AUTH0_FGA_ENVIRONMENT` variable to `"us"`. Provide the store id, client id and client secret you have created on the Dashboard.

Expand All @@ -134,7 +131,7 @@ In the playground environment, you do not need to provide a client id and client
> Learn more about [the Auth0 Fine Grained Authorization (FGA) configuration language](https://docs.fga.dev/modeling/configuration-language).
```javascript
const { authorization_model_id: id } = await auth0Fga.writeAuthorizationModel({
const { authorization_model_id: id } = await fgaClient.writeAuthorizationModel({
type_definitions: [{
type: "user",
}, {
Expand Down Expand Up @@ -164,7 +161,7 @@ const { authorization_model_id: id } = await auth0Fga.writeAuthorizationModel({

```javascript
// Assuming `1uHxCSuTP0VKPYSnkq1pbb1jeZw` is an id of a single model
const { authorization_model: authorizationModel } = await auth0Fga.readAuthorizationModel('1uHxCSuTP0VKPYSnkq1pbb1jeZw');
const { authorization_model: authorizationModel } = await fgaClient.readAuthorizationModel('1uHxCSuTP0VKPYSnkq1pbb1jeZw');

// authorizationModel = { id: "1uHxCSuTP0VKPYSnkq1pbb1jeZw", type_definitions: [...] }
```
Expand All @@ -174,7 +171,7 @@ const { authorization_model: authorizationModel } = await auth0Fga.readAuthoriza
[API Documentation](https://docs.fga.dev/api/service#/Authorization%20Models/ReadAuthorizationModels)

```javascript
const { authorization_model_ids: authorizationModelIds } = await auth0Fga.readAuthorizationModels();
const { authorization_model_ids: authorizationModelIds } = await fgaClient.readAuthorizationModels();

// authorizationModelIds = ["1uHxCSuTP0VKPYSnkq1pbb1jeZw", "GtQpMohWezFmIbyXxVEocOCxxgq"];
```
Expand All @@ -186,7 +183,7 @@ const { authorization_model_ids: authorizationModelIds } = await auth0Fga.readAu
> Provide a tuple and ask the Auth0 Fine Grained Authorization (FGA) API to check for a relationship
```javascript
const result = await auth0Fga.check({
const result = await fgaClient.check({
tuple_key: {
user: "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
relation: "viewer",
Expand All @@ -203,7 +200,7 @@ const result = await auth0Fga.check({
[API Documentation](https://docs.fga.dev/api/service#/Relationship%20Tuples/Write)

```javascript
await auth0Fga.write({
await fgaClient.write({
writes: {
tuple_keys: [{ user: "user:81684243-9356-4421-8fbf-a4f8d36aa31b", relation: "viewer", object: "document:roadmap" }],
},
Expand All @@ -217,7 +214,7 @@ await auth0Fga.write({
[API Documentation](https://docs.fga.dev/api/service#/Relationship%20Tuples/Write)

```javascript
await auth0Fga.write({
await fgaClient.write({
deletes: {
tuple_keys: [{ user: "user:81684243-9356-4421-8fbf-a4f8d36aa31b", relation: "viewer", object: "document:roadmap" }],
},
Expand All @@ -231,7 +228,7 @@ await auth0Fga.write({
[API Documentation](https://docs.fga.dev/api/service#/Relationship%20Queries/Expand)

```javascript
const { tree } = await auth0Fga.expand({
const { tree } = await fgaClient.expand({
tuple_key: {
relation: "viewer",
object: "document:roadmap",
Expand Down Expand Up @@ -283,7 +280,7 @@ const body = {
// Read all stored relationship tuples
body := {};

const { tuples } = await auth0Fga.read(body);
const { tuples } = await fgaClient.read(body);

// In all the above situations, the response will be of the form:
// tuples = [{ key: { user, relation, object }, timestamp: ... }]
Expand All @@ -297,7 +294,7 @@ const { tuples } = await auth0Fga.read(body);
const type = 'document';
const pageSize = 25;
const continuationToken = 'eyJwayI6IkxBVEVTVF9OU0NPTkZJR19hdXRoMHN0b3JlIiwic2siOiIxem1qbXF3MWZLZExTcUoyN01MdTdqTjh0cWgifQ==';
const response = await auth0Fga.readChanges(type, pageSize, continuationToken);
const response = await fgaClient.readChanges(type, pageSize, continuationToken);

// response.continuation_token = ...
// response.changes = [
Expand All @@ -311,7 +308,7 @@ const response = await auth0Fga.readChanges(type, pageSize, continuationToken);
[API Documentation](https://docs.fga.dev/api/service#/Relationship%20Queries/ListObjects)

```javascript
const response = await auth0Fga.listObjects({
const response = await fgaClient.listObjects({
authorization_model_id: "01GAHCE4YVKPQEKZQHT2R89MQV",
user: "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
relation: "viewer",
Expand Down
Loading

0 comments on commit a121bb6

Please sign in to comment.