# @elysiajs/bearer

> Elysia Pplugin for retreiving Bearer token

Latest version **1.4.4** (published 2026-04-23) · MIT license · 0 weekly downloads

## Install

```sh
npm install @elysiajs/bearer
pnpm add @elysiajs/bearer
yarn add @elysiajs/bearer
bun add @elysiajs/bearer
```

## Health

**Score 70/100 (B)** — status: stable.

Positive: has types; esm support; no vulnerabilities; has provenance; high maintenance score; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 1.4.4 |
| Published | 2026-04-23 |
| First published | 2022-12-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 57.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 17 |
| Author | saltyAom |
| Maintainers | aomkirby123 |
| Keywords | elysia, bearer, authentication |

## Links

- npm: https://www.npmjs.com/package/@elysiajs/bearer
- Repository: https://github.com/elysiajs/elysia-bearer
- Issues: https://github.com/elysiajs/elysia-bearer/issues
- npm.io page: https://npm.io/package/@elysiajs/bearer

## Alternatives

- [@pothos/plugin-authz](https://npm.io/package/@pothos/plugin-authz.md) — 12.4K weekly downloads
- [@bounded-sh/client](https://npm.io/package/@bounded-sh/client.md) — 3.2K weekly downloads
- [@luigi-project/plugin-auth-oauth2](https://npm.io/package/@luigi-project/plugin-auth-oauth2.md) — 2.3K weekly downloads
- [@nocobase/plugin-verification](https://npm.io/package/@nocobase/plugin-verification.md) — 2.0K weekly downloads
- [escher-request](https://npm.io/package/escher-request.md) — 545 weekly downloads

## Recent versions

- 1.4.4 (latest) — 2026-04-23
- 1.3.0-exp.0 (experimental) — 2025-04-22
- 1.2.0-rc.0 (rc) — 2024-12-23
- 1.0.0-beta.1 (next) — 2024-02-16
- 1.4.3 — 2026-02-02
- 1.4.2 — 2025-12-13
- 1.4.1 — 2025-09-13
- 1.4.0 — 2025-09-12
- 1.3.0 — 2025-05-05
- 1.2.0 — 2024-12-23
- 1.1.2 — 2024-09-05
- 1.1.1 — 2024-07-16
- 1.1.0 — 2024-07-16
- 1.1.0-rc.0 — 2024-07-12
- 1.0.2 — 2024-03-18
- … 24 more at https://npm.io/package/@elysiajs/bearer/versions

## README

# @elysiajs/bearer
Plugin for [elysia](https://github.com/elysiajs/elysia) for retrieving Bearer token.

This plugin is for retrieving a Bearer token specified in [RFC6750](https://www.rfc-editor.org/rfc/rfc6750#section-2).

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.

## Installation
```bash
bun add @elysiajs/bearer
```

## Example
```typescript
import { Elysia } from 'elysia'
import { bearer } from '@elysiajs/bearer'

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

                return 'Unauthorized'
            }
        }
    })
    .listen(8080)
```

## API
This plugin decorates `bearer` into `Context`.

### bearer
Extracted bearer token according to RFC6750, is either `string` or `undefined`,

If is undefined, means that there's no token provided.

## Config
Below is the configurable property for customizing the Bearer plugin.

### Extract
Custom extractor for retrieving tokens when the API doesn't compliant with RFC6750.

```typescript
/**
 * If the API doesn't compliant with RFC6750
 * The key for extracting the token is configurable
 */
extract: {
    /**
     * Determined which fields to be identified as Bearer token
     *
     * @default access_token
     */
    body?: string
    /**
     * Determined which fields to be identified as Bearer token
     *
     * @default access_token
     */
    query?: string
    /**
     * Determined which type of Authentication should be Bearer token
     *
     * @default Bearer
     */
    header?: string
}
```

---
_Source: https://npm.io/package/@elysiajs/bearer · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
