如何为 C# 中的 API 调用添加安全性?

问题描述 投票:0回答:1

我有一个这样的API方法:

[HttpPost]
[Route("GetDetails/{id}")]
public JsonResult GetDetails(string id)
{
    // ...... stuff here 
}

如何为此方法添加一些安全性,以仅允许登录应用程序的用户调用它?

c# api
1个回答
0
投票

为了安全起见,我使用 JWT 身份验证。在此处查看有关如何在 Asp Net 中将令牌添加到 API 的文档:

https://learn.microsoft.com/en-us/aspnet/core/security/authentication/jwt-authn?view=aspnetcore-8.0&tabs=windows

(PS:忘了说它是用于网页客户端)

© www.soinside.com 2019 - 2024. All rights reserved.