Skip to content

Latest commit

 

History

History
36 lines (23 loc) · 988 Bytes

File metadata and controls

36 lines (23 loc) · 988 Bytes

NestJS Example

This example demonstrates how to use the auth0-api-js package to protect API's in a NestJS application.

Install dependencies

Install the dependencies using npm:

npm install

Configuration

Rename .env.example to .env and configure the domain and audience:

AUTH0_DOMAIN=YOUR_AUTH0_DOMAIN
AUTH0_AUDIENCE=YOUR_AUTH0_AUDIENCE

With the configuration in place, the example can be started by running:

npm run start

Endpoints

The example API has the following endpoints:

  • GET /api/public: A public endpoint that can be accessed without authentication.
  • GET /api/private: A private endpoint that can only be accessed by authenticated users.
  • GET /api/private-scope: A private endpoint that can only be accessed by authenticated users with the read:private scope.

In order to call the /api/private and /api/private-scope endpoints, you need to include an Authorization header with a valid access token.