Détail du package

@elysiajs/bearer

elysiajs43.4kMIT1.3.0

Plugin for Elysia for retreiving Bearer token

elysia, bearer, authentication

readme

@elysiajs/bearer

Plugin for elysia for retrieving Bearer token.

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.

Installation

bun add @elysiajs/bearer

Example

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.

/**
 * 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
}

changelog

1.3.0-exp.0 - 23 Apr 2025

Change:

  • Add support for Elysia 1.3

1.2.0-rc.0 - 23 Dec 2024

Change:

  • Add support for Elysia 1.2

1.1.2 - 5 Sep 2024

Feature:

  • add provenance publish

1.1.1 - 16 Jul 2024

Change:

  • Accept only first bearer query

1.1.0 - 16 Jul 2024

Change:

  • Add support for Elysia 1.1

1.1.0-rc.0 - 12 Jul 2024

Change:

  • Add support for Elysia 1.1

1.0.2 - 18 Mar 2024

Change:

  • Add support for Elysia 1.0

1.0.0 - 16 Mar 2024

Change:

  • Add support for Elysia 1.0

1.0.0-rc.0 - 1 Mar 2024

Change:

  • Add support for Elysia 1.0

1.0.0-beta.1 - 17 Feb 2024

Change:

  • Add support for Elysia 1.0

1.0.0-beta.0 - 6 Feb 2024

Change:

  • Add support for Elysia 1.0

0.8.0 - 23 Dec 2023

Change:

  • Add support for Elysia 0.8

0.8.0-rc.0 - 15 Dec 2023

Change:

  • Add support for Elysia 0.8

0.7.0 - 20 Sep 2023

  • Add support for Elysia 0.7

0.7.0-beta.0 - 18 Sep 2023

  • Add support for Elysia 0.7

0.6.0 - 6 Aug 2023

  • Add support for Elysia 0.6

0.6.0-rc.0 - 6 Aug 2023

  • Add support for Elysia 0.6

    0.5.0 - 15 May 2023

  • Add support for Elysia 0.5
  • Add CommonJS support

0.3.0 - 30 Mar 2023

Improvement:

  • Add support for Elysia 0.3.0

0.1.0-rc.3 - 13 Dec 2022

Improvement:

  • Add support for Elysia 0.1.0-rc.5

0.1.0-rc.2 - 9 Dec 2022

Fix:

  • Add main fields Bundlephobia

0.1.0-rc.1 - 6 Dec 2022

Improvement:

  • Support for Elysia 0.1.0-rc.1 onward

0.0.0-experimental.1 - 1 Dec 2022

Improvement:

  • using .inject instead of hacking with Object.assign