Skip to content

承载器插件

¥Bearer Plugin

用于检索 Bearer 令牌的 elysia 插件。

¥Plugin for elysia for retrieving the Bearer token.

使用以下工具安装:

¥Install with:

bash
bun add @elysiajs/bearer

然后使用它:

¥Then use it:

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

此插件用于检索 RFC6750 中指定的 Bearer 令牌。

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

此插件不处理你服务器的身份验证。相反,该插件将决定权留给开发者,让他们自己应用逻辑来处理验证检查。

¥This plugin DOES NOT handle authentication validation for your server. Instead, the plugin leaves the decision to developers to apply logic for handling validation check themselves.