0
0
mirror of https://github.com/honojs/hono.git synced 2024-11-29 17:46:30 +01:00
hono/deno_dist/middleware/bearer-auth
2022-07-02 22:31:10 +09:00
..
index.ts feat: support Deno! (#336) 2022-07-02 15:09:45 +09:00
README.md feat: support Deno! (#336) 2022-07-02 15:09:45 +09:00

Bearer Auth Middleware

Usage

import { Hono } from 'hono'
import { bearerAuth } from 'hono/bearer-auth'

const app = new Hono()

const token = 'honoisacool'

app.use('/auth/*', bearerAuth({ token }))

app.get('/auth/page', (c) => {
  return c.text('You are authorized')
})

app.fire()

Options

app.use(
  '/auth/*',
  bearerAuth({
    token: 'honoisacool', // Required
    realm: 'example.com',
    prefix: 'Bot'
    hashFunction: (d: string) => SHA256(d).toString(), // For Fastly Compute@Edge
  })
)