0.0.10 • Published 11 months ago

@meistrari/data-token v0.0.10

Weekly downloads
-
License
UNLICENSED
Repository
-
Last release
11 months ago

@meistrari/data-token

Internal library to verify and decode the API Gateway data token.

Installation

pnpm install @meistrari/data-token

Usage

Basic Usage (No Adapter)

import { getValidator } from '@meistrari/data-token'

const validator = getValidator('https://some.api.com/well-known/jwks.json')

async function validateToken(token: string): Promise<DataToken> {
  return await validator(token)
}

Usage with Hono

import { Hono } from 'hono'
import { DataTokenContext, createDataTokenMiddleware } from '@meistrari/data-token/hono'

// Combine DataTokenContext with your own context type
type Env = {
  Variables: {
    customProp: string
  }
}
type AppContext = Env & DataTokenContext

const app = new Hono<AppContext>()
const dataToken = createDataTokenMiddleware('https://some.api.com/well-known/jwks.json')

app.use(dataToken)

app.get('/', (c) => {
  const authData = c.get('authData')
  return c.json({ data: authData })
})

Usage with Elysia

import { Elysia } from 'elysia'
import { createDataTokenPlugin } from '@meistrari/data-token/elysia'

const app = new Elysia()

const dataToken = createDataTokenPlugin('https://some.api.com/well-known/jwks.json')

app
  .use(dataToken)
  .get('/', ({ authData }) => ({ authData }))

API Reference

getValidator(jwksUrl: string, options?: { algorithms?: string[] })

Creates a validator function that can be used to validate and decode tokens.

createDataTokenMiddleware(url: string, getToken?: (c: Context) => string)

Creates a Hono middleware for token validation.

createDataTokenPlugin(url: string, getToken?: (c: Context) => string)

Creates an Elysia plugin for token validation.

Types

The DataToken type, as well as a Zod schema for the token payload is available from the /types entrypoint, both under the name of DataToken:

import { DataToken } from '@meistrari/data-token/types'

This type represents the structure of the decoded token data.

0.0.10

11 months ago

0.0.9

12 months ago

0.0.8

1 year ago

0.0.7

1 year ago

0.0.6

1 year ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago