简体   繁体   English

如何在不同的基于Owin的相关MVC应用程序和Web API之间使用一个用户凭证?

[英]How to use one user credential across different related Owin-based MVC apps and web APIs?

I have an Owin-based MVC application which uses my web api to provide many functionalities. 我有一个基于Owin的MVC应用程序,它使用我的Web api提供许多功能。 At the moment the user should login to both of them separately (using ajax calls, at the login page I do the login for web api and receive the token as well), but both use the same table, so there is only one place to store the user information. 目前,用户应分别登录两个用户(使用ajax调用,在登录页面上,我也登录Web api并接收令牌),但是两者都使用同一张表,因此只有一个地方可以存储用户信息。

Unfortunately other MVC applications are using separate username and passwords and are not using the mentioned api. 不幸的是,其他MVC应用程序正在使用单独的用户名和密码,并且未使用所提到的api。 As now I should create a new MVC app which is again the same domain I am looking for a way to use a single username and password (managed by one main MVC app) for whatever reason it's needed, ie, all the MVC apps and the web APIs use the same username and password, and therefore for example I can use the [Authorize] attribute or roles, ... in all of them. 现在,我应该创建一个新的MVC应用程序,该应用程序还是同一个域。我正在寻找一种出于任何原因使用单一用户名和密码(由一个主MVC应用程序管理)的方法,即所有MVC应用程序和Web API使用相同的用户名和密码,因此,例如,我可以在所有API中使用[Authorize]属性或角色。

Is there any known solution for this? 有没有已知的解决方案? Does Creating an OAuth authorization server suit this problem? 创建OAuth授权服务器是否适合此问题?

Implementing Single-Sign on using OpenID Connect on top of OAuth2 fits your requirement. 在OAuth2之上使用OpenID Connect实现单点登录符合您的要求。 checkout identityServer3 or identityServer4 if you are using .net core. 如果使用的是.net core,请检出identityServer3或identityServer4。

basically, you will need to setup a shared STS authority, and all your applications will use this authority to validate a requests using a OWIN middleware to check for token validity. 基本上,您将需要设置共享的STS权限,并且所有应用程序都将使用此权限来使用OWIN中间件来检查令牌的有效性,以验证请求。

On first login, The STS authority will issue a token for the user, and you will need to manage through your front-end/back-end code, re-using the token when navigating across multiple applications/domains. 首次登录时,STS机构将为用户颁发令牌,并且您将需要通过前端/后端代码进行管理,从而在跨多个应用程序/域导航时重新使用令牌。

C# ASP.NET Single Sign-On Implementation C#ASP.NET单一登录实现

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM