@elysiajs/ 守护者
插件用于 爱乐 用来取回熊鼠的标志.
此插件用于重取在 RFC6750 (法语)。 。 。 .
此插件 没有 处理您的服务器的认证验证, 相反, 插件会让开发者 应用逻辑来检查它们本身 .
安装
bun add @elysiajs/bearer
示例
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 密码
此插件装饰 bearer 输入 Context。 。 。 .
无记名者
根据RFC6750,提取的无记名代号是 string 或者说 undefined, (中文(简体) ),
如果未定义,则意味着没有提供任何标志.
配置
以下是用于自定义Bearer插件的可配置属性.
摘录
当API不符合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
}