Skip to content
在 AI 工具中打开 Anthropic

Bearer 插件

用于 elysia 的插件,用于获取 Bearer 令牌。

通过以下命令安装:

bash
bun add @elysiajs/bearer

然后使用它:

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 DOES NOT handle authentication validation for your server. Instead, the plugin leaves the decision to developers to apply the logic for handling validation checks themselves.