如何通过用户名/密码&amp ;;实现ASP.NET Web API身份验证客户端ID / ClientSecret

时间:2017-06-07 06:54:04

标签: security asp.net-web-api

我的Web API为2个不同类别的消费者提供服务。 1.使用ID和密码登录的实际最终用户。 2.通过API与我的应用程序集成的另一个应用程序。

为此类系统实施身份验证和授权时,最佳做法是什么?

我在这里有两个解决方案:

Using the same Web API project for both web app and API

图1.对Web应用程序和API使用相同的Web API项目

Using different Web API project for web app and API separately.

图2.分别为Web应用和API使用不同的Web API项目。

图2中的解决方案更直接地实现了身份验证层。但它可能在两个项目中都有重复的API端点(尽管大多数业务逻辑都包含在服务层中)。

这里最好的解决方案是什么? 如果图1是更好的解决方案,那么我该如何实现授权层?任何能实现这一目标的图书馆? 请指教。

1 个答案:

答案 0 :(得分:0)

对于身份验证和授权,您可以在asp.net中使用identity和Owin

检查此链接以进行身份​​验证和授权

http://johnatten.com/2014/10/26/asp-net-web-api-and-identity-2-0-customizing-identity-models-and-implementing-role-based-authorization/

http://bitoftech.net/2014/06/01/token-based-authentication-asp-net-web-api-2-owin-asp-net-identity/

或者您可以尝试使用guid()生成令牌;