Skip to content

Bearer plugin

Plugin for elysia for retrieving the Bearer token.

Install with:

Terminal window
bun add @elysia/bearer@next

Then use it:

import { Elysia } from 'elysia'
import { bearer } from '@elysia/bearer'
const app = new Elysia()
.use(bearer())
.get('/sign', {
beforeHandle({ bearer, set, status }) {
if (!bearer) {
set.headers[
'WWW-Authenticate'
] = `Bearer realm="sign"`
return status(401, 'Unauthorized')
}
}
}, ({ bearer }) => bearer)
.listen(3000)

This plugin is for retrieving a Bearer token specified in RFC6750.

This plugin extracts the token. It does not authenticate the request or validate the token; add those checks in your application.

Type to search the documentation.

    Up arrowDown arrow to navigateEnter to selectEscape to close