Skip to content

CyrusBiotechnology/auth0-authorization

Repository files navigation

auth0-authorization

Auth0 Authorization Extension API client library

Installation

  npm install @cyrusbio/auth0-authorization

AuthorizationClient

Use this client to access the Auth0 Authorization Extension API.

import { AuthorizationClient } from '@cyrusbio/auth0-authorization';

const authorization = new AuthorizationClient({
  clientId: `${CLIENT_ID}`,
  clientSecret: `${CLIENT_SECRET}`,
  domain: `${TENANT}.auth0.com`,
  extensionUrl: `https://${TENANT}.us.webtask.io/xxx/api`,
});

Behind the scenes the client obtains an access token, caches it, and automatically refreshes it if it expires.

Each method returns a promise.

const groups = await authorization.getGroups();

Types

TypeScript types are included.

import { IAuth0AuthorizationApiGroup } from '@cyrusbio/auth0-authorization';

let group: IAuth0AuthorizationApiGroup;

Testing

All tests run against a live Auth0 tenant instance.

Configuration

First you need to set up a .env file containing the Auth0 configuration. Here is an example .env that includes all non-secret values (cyrusbio-identity-lib is an Auth0 tenant made specifically for testing this library):

cat <<'EOF' > .env
AUTH0_DOMAIN=xxx
AUTH0_CLIENT_ID=xxx
AUTH0_CLIENT_SECRET=xxx
AUTH0_EXTENSION_URL=xxx
EOF

Run all tests

env $(cat .env | xargs) npm test

Run individual test

npm run testbuild
env $(cat .env | xargs) node_modules/.bin/ava test/[test-name].spec.js

Logging in tests

Logging in tests should use ava t.log instead of console.log. Those logs will appear only when running ava in verbose mode:

env $(cat .env | xargs) node_modules/.bin/ava test/[test-name].spec.js --verbose

About

Auth0 Authorization Extension API client library

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published