@antelopejs/interface-auth
藏羚羊JS的令牌认证合同:签署并验证令牌,并用装饰器将已核实的有效载荷注入API处理器.
部分 羚羊JS, 模块依赖合同且应用程序选择提供者的TypeScript框架. 由后面的团队建造 羚羊JS 隐形物。 。 。 .
它提供的东西
SignRaw财务报告和审定财务报表ValidateRaw将有效载荷签入一个代号,并核实一个代号返回其有效载荷.SignServerResponse签署有效载荷,并将该符号作为饼干附在反应上.@Authentication()从x-antelopejs-auth标题,或来自ANTELOPEJS_AUTH当信头缺席时做曲奇. 它验证了符号,并将有效载荷注入了处理器参数.CreateAuthDecorator使用自定义的源、 校验器和校验器构建您的装饰 .
执行情况
| 模块 | 页:1 |
|---|---|
@antelopejs/auth-jwt | JSON 网络键 |
安装
将界面添加到保护路径的模块中 :
pnpm add @antelopejs/interface-auth
然后在项目中添加一个执行,同时实施API接口:
ajs project modules add @antelopejs/auth-jwt @antelopejs/api
快开始
import { Controller, Get, Post } from "@antelopejs/interface-api";
import { Authentication, SignRaw } from "@antelopejs/interface-auth";
interface Session {
id: string;
}
export class SessionController extends Controller("/session") {
@Post("login")
async login() {
return SignRaw({ id: "user-7" }, { expiresIn: "1h" });
}
@Get("me")
async me(@Authentication() session: Session) {
return { id: session.id };
}
}
请求 GET /session/me 处理器运行前没有有效的符号失败 。 发送符号不变 x-antelopejs-auth,没有 Bearer 前缀。 这个 login 方法只显示签名。 在真正的申请中,在签发代币前先检查证书.
这个 Session 注释描述应用程序预期的有效载荷。 它不检查它,所以 session.id 无论是什么 已经核实的标志携带。 添加一个 形状检查验证器 之前,您要依赖任何格式都无法执行的标志.
文档
兼容性
模块宣布这些对等关系:
| 软件包 | 支助 | 测试过 |
|---|---|---|
@antelopejs/interface-api | >=0.0.15 <1.0.0 | 0.2.0 |
@antelopejs/interface-core | >=0.2.4 <1.0.0 | 0.4.0 |
捐款
读取 捐款额 在你打开拉动请求之前。 当地检查为:
pnpm install
pnpm lint
pnpm test