我有一个回送功能,它使用它自己的特殊身份验证形式。我不想将这个身份验证阶段与端点本身分开进行。我想在端点代码中进行身份验证。
为了执行此操作,我需要访问Authorization标头。
如何在回送控制器功能中执行此操作?
@get('/item/{itemId}', {
description: `Get a specific item`,
responses: {}
})
async getItem(
@param.path.string('itemId') itemId: string,
): Promise<LabResult[]> {
// How do I get headers from here?
const auth = somehowGetHeaders().get("Authorization");
}
您可以通过注入请求对象来访问标题。例如 。 。 。
@get('/item/{itemId}', {
description: `Get a specific item`,
responses: {}
})
async getItem(
@param.path.string('itemId') itemId: string,
@inject(RestBindings.Http.REQUEST) private req: Request
): Promise<LabResult[]> {
console.log('headers', req.headers);
// using header information here you can authenticate
}