Skip to content

Gabrielpanga/vercel-upstash-tokens-cache

Repository files navigation

AccessToken Cache Microservice

This application is meant to serve as an internal service to recover Auth0 M2M token for internal microservice communications.

Creating this tokens in serverless can increase the usaged quota of your Auth0 subscription, so the goal is to reuse the accessToken for the expiration provided by auth0 until a new one is requested.

The tokens are stored in Upstash

This is a Next.js project bootstrapped with create-next-app.

Set up

First clone the repo. Copy the .env.local.example file to .env.local (which will be ignored by Git):

cp .env.local.example .env.local

Configuring Upstash

  1. Go to the Upstash Console and create a new database

Upstash environment

UPSTASH_REDIS_REST_URL and UPSTASH_REDIS_REST_TOKEN find the variables in the database details page in Upstash Console.

Auth0 environment

  • AUTH0_DOMAIN: Can be found in the Auth0 dashboard under settings.
  • AUTH0_CLIENT_ID: Can be found in the Auth0 dashboard under settings.
  • AUTH0_CLIENT_SECRET: Can be found in the Auth0 dashboard under settings.

Getting Started

First, run the development server:

npm run dev
# or
yarn dev

Open http://localhost:3000 with your browser to see the result.

You can start editing the page by modifying pages/index.tsx. The page auto-updates as you edit the file.

API routes can be accessed on http://localhost:3000/api/token. This endpoint can be edited in pages/api/token.ts.

This is a mocked endpoint to provide the M2M token as an easy way to validate the usage.

Tools used

  • Vercel for deployment & development environment.
  • Next.js with typescript support to run the application
  • Upstash for Serverless Redis (cache).
  • Auth0 for authorization management.

About

Microservice to cache auth0 m2m access tokens

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published