我有一个这样的API方法:
[HttpPost] [Route("GetDetails/{id}")] public JsonResult GetDetails(string id) { // ...... stuff here }
如何为此方法添加一些安全性,以仅允许登录应用程序的用户调用它?
为了安全起见,我使用 JWT 身份验证。在此处查看有关如何在 Asp Net 中将令牌添加到 API 的文档:
https://learn.microsoft.com/en-us/aspnet/core/security/authentication/jwt-authn?view=aspnetcore-8.0&tabs=windows
(PS:忘了说它是用于网页客户端)