Bearer Plugin

Plugin for elysia for retreiving Bearer token.

Install with:

bun add @elysiajs/bearer

Then use it:

import { Elysia } from "elysia";
import { bearer } from "@elysiajs/bearer";

const app = new Elysia()
  .get("/sign", ({ bearer }) => bearer, {
    beforeHandle({ bearer, set }) {
      if (!bearer) {
        set.status = 400;
        set.headers["WWW-Authenticate"] = `Bearer realm='sign', error="invalid_request"`;

        return "Unauthorized";

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

This plugin DOES NOT handle authentication validation for your server, rather the plugin leaves the decision for developers to apply logic for handle validation check themself.