0.5.1 • Published 2 years ago

sandcastle-sdk v0.5.1

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

JavaScript and Node.js SDK for Auth0 Fine Grained Authorization (FGA)

FOSSA Status

DEPRECATION NOTICE: This SDK has been deprecated in favour of @auth0/fga. Please install it from there.

This is an autogenerated JavaScript SDK for Auth0 Fine Grained Authorization (FGA). It provides a wrapper around the Auth0 Fine Grained Authorization API, and includes TS typings.

Warning: This SDK comes with no SLAs and is not production-ready!

Table of Contents

About Auth0 Fine Grained Authorization

Auth0 Fine Grained Authorization (FGA) is the early-stage product we are building at Auth0 as part of Auth0Lab to solve fine-grained authorization at scale. If you are interested in learning more about our plans, please reach out via our Discord chat.

Please note:

  • At this point in time, Auth0 Fine Grained Authorization does not come with any SLAs; availability and uptime are not guaranteed.
  • While this project is in its early stages, the SDK methods are in flux and might change without a major bump

Resources

Installation

Using npm:

npm install @auth0/fga

Using yarn:

yarn add @auth0/fga

Getting Started

Initializing the API Client

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

const auth0Fga = new Auth0FgaApi({
  environment: AUTH0_FGA_ENVIRONMENT,
  storeId: AUTH0_FGA_STORE_ID,
  clientId: AUTH0_FGA_CLIENT_ID,
  clientSecret: AUTH0_FGA_CLIENT_SECRET,
});

Getting your Store ID, Client ID and Client Secret

Production

Make sure you have created your credentials on the Auth0 FGA Dashboard. Learn how ➡

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.

PoC

If you are an Auth0 FGA PoC participant, you need to set the AUTH0_FGA_ENVIRONMENT variable to "poc". Provide the store id, client id and client secret you have received from us.

Playground

If you are testing this on the public playground, you need to set your AUTH0_FGA_ENVIRONMENT to "playground".

To get your store id, you may copy it from the store you have created on the Playground. Learn how ➡

In the playground environment, you do not need to provide a client id and client secret.

Calling the API

Write Authorization Model

Note: To learn how to build your authorization model, check the Docs at https://docs.fga.dev/

Note: The Auth0 FGA Playground, Dashboard and Documentation use a friendly syntax which gets translated to the API syntax seen below. Learn more about the Auth0 FGA configuration language.

const { id } = await auth0Fga.writeAuthorizationModel({
  type_definitions: [{
    type: "repo",
    relations: {
      "writer": { "this": {} },
      "reader": {
        "union": {
          "child": [
            { "this": {} },
            { "computedUserset": {
               "object": "",
              "relation": "writer" }
            }
          ]
        }
      }
    } }],
});

// id = "1uHxCSuTP0VKPYSnkq1pbb1jeZw"

Read a Single Authorization Model

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

// authorizationModel = { id: "1uHxCSuTP0VKPYSnkq1pbb1jeZw", type_definitions: [...] }

Read Authorization Model IDs

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

// authorizationModelIds = ["1uHxCSuTP0VKPYSnkq1pbb1jeZw", "GtQpMohWezFmIbyXxVEocOCxxgq"];

Check

Provide a tuple and ask the Auth0 FGA API to check for a relationship

const result = await auth0Fga.check({
  tuple_key: {
    user: "81684243-9356-4421-8fbf-a4f8d36aa31b",
    relation: "admin",
    object: "workspace:675bcac4-ad38-4fb1-a19a-94a5648c91d6",
  },
});

// result = { allowed: true, resolution: "" }

Write Tuples

await auth0Fga.write({
  writes: {
    tuple_keys: [{ user: "anne", relation: "reader", object: "repo:auth0/express-jwt" }],
  },
});

Delete Tuples

await auth0Fga.write({
  deletes: {
    tuple_keys: [{ user: "anne", relation: "reader", object: "repo:auth0/express-jwt" }],
  },
});

Expand

const { tree } = await auth0Fga.expand({
  tuple_key: {
    relation: "admin",
    object: "workspace:675bcac4-ad38-4fb1-a19a-94a5648c91d6",
  },
});

// tree = {...}

Read

// Find if a relationship tuple stating that a certain user is an admin on a certain workspace
const body = {
  tuple_key: {
    user: "81684243-9356-4421-8fbf-a4f8d36aa31b",
    relation: "admin",
    object: "workspace:675bcac4-ad38-4fb1-a19a-94a5648c91d6",
  },
};

// Find all relationship tuples where a certain user has a relationship as any relation to a certain workspace
const body = {
  tuple_key: {
    user: "81684243-9356-4421-8fbf-a4f8d36aa31b",
    object: "workspace:675bcac4-ad38-4fb1-a19a-94a5648c91d6",
  },
};

// Find all relationship tuples where a certain user is an admin on any workspace
const body = {
  tuple_key: {
    user: "81684243-9356-4421-8fbf-a4f8d36aa31b",
    relation: "admin",
    object: "workspace:",
  },
};

// Find all relationship tuples where any user has a relationship as any relation with a particular workspace
const body = {
  tuple_key: {
    object: "workspace:675bcac4-ad38-4fb1-a19a-94a5648c91d6",
  },
};

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

// In all the above situations, the response will be of the form:
// tuples = [{ key: { user, relation, object }, timestamp: ... }]

API Endpoints

MethodHTTP requestDescription
checkPOST /{store_id}/checkCheck whether a user is authorized to access an object
deleteTokenIssuerDELETE /{store_id}/settings/token-issuers/{id}Remove 3rd party token issuer for Auth0 FGA read and write operation
expandPOST /{store_id}/expandExpand all relationships in userset tree format, and following userset rewrite rules. Useful to reason about and debug a certain relationship
readPOST /{store_id}/readGet tuples from the store that matches a query, without following userset rewrite rules
readAssertionsGET /{store_id}/assertions/{authorization_model_id}Read assertions for an authorization model ID
readAuthorizationModelGET /{store_id}/authorization-models/{id}Return a particular version of an authorization model
readAuthorizationModelsGET /{store_id}/authorization-modelsReturn all the authorization model IDs for a particular store
readSettingsGET /{store_id}/settingsReturn store settings, including the environment tag
writePOST /{store_id}/writeAdd or delete tuples from the store
writeAssertionsPOST /{store_id}/assertions/{authorization_model_id}Upsert assertions for an authorization model ID
writeAuthorizationModelPOST /{store_id}/authorization-modelsCreate a new authorization model
writeSettingsPATCH /{store_id}/settingsUpdate the environment tag for a store
writeTokenIssuerPOST /{store_id}/settings/token-issuersAdd 3rd party token issuer for Auth0 FGA read and write operations

check

NameTypeDescriptionNotes
bodyCheckRequestParams
Return type

CheckResponse

deleteTokenIssuer

NameTypeDescriptionNotes
idstringId of token issuer to be removeddefault to undefined
Return type

object

expand

NameTypeDescriptionNotes
bodyExpandRequestParams
Return type

ExpandResponse

read

NameTypeDescriptionNotes
bodyReadRequestParams
Return type

ReadResponse

readAssertions

NameTypeDescriptionNotes
authorizationModelIdstringThe authorization model IDdefault to undefined
Return type

ReadAssertionsResponse

readAuthorizationModel

NameTypeDescriptionNotes
idstringThe authorization model IDdefault to undefined
Return type

ReadAuthorizationModelResponse

readAuthorizationModels

NameTypeDescriptionNotes
pageSizenumberdefault to undefinedcontinuationTokenstringdefault to undefined
Return type

ReadAuthorizationModelsResponse

readSettings

NameTypeDescriptionNotes
Return type

Settings

write

NameTypeDescriptionNotes
bodyWriteRequestParams
Return type

object

writeAssertions

NameTypeDescriptionNotes
authorizationModelIdstringThe authorization model IDdefault to undefinedbodyWriteAssertionsRequestParams
Return type

object

writeAuthorizationModel

NameTypeDescriptionNotes
bodyTypeDefinitions
Return type

WriteAuthorizationModelResponse

writeSettings

NameTypeDescriptionNotes
bodyWriteSettingsRequestParams
Return type

Settings

writeTokenIssuer

NameTypeDescriptionNotes
bodyWriteTokenIssuersRequestParams
Return type

TokenIssuer

Models

Any

Properties
NameTypeDescriptionNotes
typestringoptional

Assertion

Properties
NameTypeDescriptionNotes
tuple_keyTupleKeydefault to undefined
expectationbooleandefault to undefined

AuthorizationModel

Properties
NameTypeDescriptionNotes
idstringoptional
type_definitionsTypeDefinition[]optional

AuthorizationmodelDifference

Properties
NameTypeDescriptionNotes
baseUsersetdefault to undefined
subtractUsersetdefault to undefined

AuthorizationmodelTupleToUserset

Properties
NameTypeDescriptionNotes
tuplesetObjectRelationoptional
computedUsersetObjectRelationoptional

CheckRequestParams

Properties
NameTypeDescriptionNotes
tuple_keyTupleKeyoptional
authorization_model_idstringoptional
tracebooleandefaults to false. making it true has performance implications. only use for debugging purposes, etc.optional default to undefined

CheckResponse

Properties
NameTypeDescriptionNotes
allowedbooleanoptional
resolutionstringoptional

Computed

Properties
NameTypeDescriptionNotes
usersetstringoptional

Environment

Enum
  • EnvironmentUnspecified (value: 'ENVIRONMENT_UNSPECIFIED')

  • Development (value: 'DEVELOPMENT')

  • Staging (value: 'STAGING')

  • Production (value: 'PRODUCTION')

ExpandRequestParams

Properties
NameTypeDescriptionNotes
tuple_keyTupleKeyoptional
authorization_model_idstringoptional

ExpandResponse

Properties
NameTypeDescriptionNotes
treeUsersetTreeoptional

Leaf

Properties
NameTypeDescriptionNotes
usersUsersoptional
computedComputedoptional
tupleToUsersetUsersetTreeTupleToUsersetoptional

Node

Properties
NameTypeDescriptionNotes
namestringoptional
leafLeafoptional
differenceUsersetTreeDifferenceoptional
unionNodesoptional
intersectionNodesoptional

Nodes

Properties
NameTypeDescriptionNotes
nodesNode[]optional

ObjectRelation

Properties
NameTypeDescriptionNotes
objectstringoptional
relationstringoptional

ReadAssertionsResponse

Properties
NameTypeDescriptionNotes
authorization_model_idstringThe authorization model IDoptional
assertionsAssertion[]optional

ReadAuthorizationModelResponse

Properties
NameTypeDescriptionNotes
authorization_modelAuthorizationModeloptional

ReadAuthorizationModelsResponse

Properties
NameTypeDescriptionNotes
authorization_model_idsstringoptional
continuation_tokenstringoptional

ReadRequestParams

Properties
NameTypeDescriptionNotes
tuple_keyTupleKeyoptional
authorization_model_idstringoptional

ReadResponse

Properties
NameTypeDescriptionNotes
tuplesTuple[]optional

ReadTuplesRequestParams

Properties
NameTypeDescriptionNotes
page_sizenumberoptional
continuation_tokenstringoptional

ReadTuplesResponse

Properties
NameTypeDescriptionNotes
tuplesTuple[]optional
continuation_tokenstringoptional

Settings

Properties
NameTypeDescriptionNotes
environmentEnvironmentoptional
token_issuersTokenIssuer[]optional

Status

Properties
NameTypeDescriptionNotes
codenumberoptional
messagestringoptional
detailsAny[]optional

TokenIssuer

Properties
NameTypeDescriptionNotes
idstringoptional
issuer_urlstringoptional

Tuple

Properties
NameTypeDescriptionNotes
keyTupleKeyoptional
timestampstringoptional

TupleKey

Properties
NameTypeDescriptionNotes
objectstringoptional
relationstringoptional
userstringoptional

TupleKeys

Properties
NameTypeDescriptionNotes
tuple_keysTupleKey[]default to undefined

TypeDefinition

Properties
NameTypeDescriptionNotes
typestringdefault to undefined
relationsRecord<string, Userset>default to undefined

TypeDefinitions

Properties
NameTypeDescriptionNotes
type_definitionsTypeDefinition[]optional

Users

Properties
NameTypeDescriptionNotes
usersstringoptional

Userset

Properties
NameTypeDescriptionNotes
_thisobjectA DirectUserset is a sentinel message for referencing the direct members specified by an object/relation mapping.optional
computedUsersetObjectRelationoptional
tupleToUsersetAuthorizationmodelTupleToUsersetoptional
unionUsersetsoptional
intersectionUsersetsoptional
differenceAuthorizationmodelDifferenceoptional

UsersetTree

Properties
NameTypeDescriptionNotes
rootNodeoptional

UsersetTreeDifference

Properties
NameTypeDescriptionNotes
baseNodeoptional
subtractNodeoptional

UsersetTreeTupleToUserset

Properties
NameTypeDescriptionNotes
tuplesetstringoptional
computedComputed[]optional

Usersets

Properties
NameTypeDescriptionNotes
childUserset[]optional

WriteAssertionsRequestParams

Properties
NameTypeDescriptionNotes
assertionsAssertion[]default to undefined

WriteAuthorizationModelResponse

Properties
NameTypeDescriptionNotes
authorization_model_idstringoptional

WriteRequestParams

Properties
NameTypeDescriptionNotes
writesTupleKeysoptional
deletesTupleKeysoptional
authorization_model_idstringoptional
lock_tupleTupleoptional

WriteSettingsRequestParams

Properties
NameTypeDescriptionNotes
environmentEnvironmentoptional

WriteTokenIssuersRequestParams

Properties
NameTypeDescriptionNotes
issuer_urlstringoptional

Issue Reporting

If you have found a bug or if you have a feature request, please report them at this repository issues section. Please do not report security vulnerabilities on the public GitHub issue tracker. The Responsible Disclosure Program details the procedure for disclosing security issues.

For auth0 related questions/support please use the Support Center.

Pull Requests

Pull Requests are not currently open, please raise an issue or contact a team member on https://discord.gg/8naAwJfWN6 if there is a feature you'd like us to implement.

Author

Auth0Lab

License

This project is licensed under the MIT license. See the LICENSE file for more info.

The code in this repo was auto generated by OpenAPI Generator from a template based on the typescript-axios template and go template, licensed under the Apache License 2.0.

0.4.0

2 years ago

0.5.1

2 years ago

0.3.0

2 years ago

0.3.1

2 years ago

0.2.0

3 years ago

0.1.2

3 years ago

0.0.5

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago

0.0.4

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago