Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/cyrusbiotechnology/auth0-authorization
Auth0 Authorization Extension API client library
https://github.com/cyrusbiotechnology/auth0-authorization
auth0 typescript
Last synced: 2 months ago
JSON representation
Auth0 Authorization Extension API client library
- Host: GitHub
- URL: https://github.com/cyrusbiotechnology/auth0-authorization
- Owner: CyrusBiotechnology
- License: bsd-2-clause
- Created: 2018-12-12T10:28:37.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2024-06-20T18:27:23.000Z (8 months ago)
- Last Synced: 2024-11-29T16:04:38.761Z (2 months ago)
- Topics: auth0, typescript
- Language: TypeScript
- Homepage:
- Size: 831 KB
- Stars: 0
- Watchers: 9
- Forks: 3
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# auth0-authorization
Auth0 Authorization Extension API client library
## Installation
```bash
npm install @cyrusbio/auth0-authorization
```## AuthorizationClient
Use this client to access the [Auth0 Authorization Extension API](https://auth0.com/docs/api/authorization-extension).
```ts
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.
```ts
const groups = await authorization.getGroups();
```## Types
[TypeScript](https://www.typescriptlang.org) types are included.
```ts
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):```bash
cat <<'EOF' > .env
AUTH0_DOMAIN=xxx
AUTH0_CLIENT_ID=xxx
AUTH0_CLIENT_SECRET=xxx
AUTH0_EXTENSION_URL=xxx
EOF
```### Run all tests
```bash
env $(cat .env | xargs) npm test
```### Run individual test
```bash
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:```bash
env $(cat .env | xargs) node_modules/.bin/ava test/[test-name].spec.js --verbose
```