Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我的 ASP.NET API 当前接受来自经过身份验证和注册的用户的请求。我想添加一些新的 API 方法,它们应该只响应来自某些应用程序的请求——比如我创建的网站。
如何在我的 ASP.NET API 应用程序中处理这种“应用程序身份验证”方案?
KEY简单的方法是在服务器将验证的请求标头中传递一些密钥 [ ]。为了使其更安全并确保没有中间人可以嗅探您的密钥,更好的方法是传递与sha 函数sha(KEY:timestamp)一起使用的令牌。timestamp
KEY
sha(KEY:timestamp)
timestamp
一旦您在 API 服务器上收到此类请求,您应该验证收到的时间戳不是太旧/过期并构造 serverToken= sha(KEY:timestamp)。如果标头中的令牌与 serverToken 相同,则请求已通过身份验证。