ASP.NETIdentity的中央登录/身份验证应用程序用于两个分开的ASP.NETMVC应用程序。
创始人
2024-09-19 00:01:13
0

使用ASP.NET Identity创建中央身份验证服务,用于身份验证并共享用户凭据。在两个分别的ASP.NET MVC应用程序中,配置以使用相同的中央身份验证服务进行身份验证。

例如,我们可以创建一个名为"CentralAuth"的ASP.NET Identity项目,并配置其作为中央身份验证服务。然后,在两个分别的ASP.NET MVC应用程序中,使用以下代码配置身份验证:

// 在Startup.Auth.cs文件中

app.CreatePerOwinContext(ApplicationUserManager.Create);
app.CreatePerOwinContext(ApplicationSignInManager.Create);

app.UseCookieAuthentication(new CookieAuthenticationOptions
{
   AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
   LoginPath = new PathString("/Account/Login"),
   Provider = new CookieAuthenticationProvider
   {
      OnValidateIdentity = SecurityStampValidator.OnValidateIdentity(
      validateInterval: TimeSpan.FromMinutes(30),
      regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
   }
});

app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);

app.UseCentralizedOAuth(new CentralizedOAuthOptions()){
    AuthenticationMode = AuthenticationMode.Passive,
    ClientId = "myAppId",
    ClientSecret = "myAppSecret"
});

// 在Web.Config文件中



然后,在两个应用程序中定义UseCentralizedOAuth方法:

// 在Controllers/AccountController.cs文件中

public ActionResult ExternalLoginCallback(string returnUrl)
{
   var ctx = Request.GetOwinContext();
   var authManager = ctx.Authentication;

   var loginInfo = authManager.GetExternalLoginInfoAsync().Result;
   if (loginInfo == null)
   {
      return RedirectToAction("Login");
   }

   var userManager = HttpContext.GetOwinContext().GetUserManager();
   var user = userManager.FindAsync(loginInfo.Login).Result;
   if (user != null)
   {
      authManager.SignIn(new AuthenticationProperties { IsPersistent = false }, user.GenerateUserIdentityAsync

相关内容

热门资讯

透视辅助!德普辅助软件(透视)... 透视辅助!德普辅助软件(透视)德普之星透视软件免费入口官网-果然存在有挂(哔哩哔哩)1、完成德普之星...
透视模拟器!wepoker辅助... 透视模拟器!wepoker辅助器(透视)wepoker软件辅助程序-都是存在有挂(哔哩哔哩)1、让任...
据悉!aapoker公共底牌(... 据悉!aapoker公共底牌(透视)hhpoker是正品吗-都是存在有挂(哔哩哔哩)1、据悉!aap...
透视科技!wpk真的有透视嘛(... 透视科技!wpk真的有透视嘛(透视)wpk真的有透视嘛-果然有挂(哔哩哔哩)1)wpk真的有透视嘛有...
今年以来!aapoker辅助怎... 今年以来!aapoker辅助怎么用(透视)hhpoker辅助挂下载-一贯是有挂(哔哩哔哩)aapok...
透视插件!aapoker怎么拿... 透视插件!aapoker怎么拿好牌(透视)德州hhpoker脚本-本来存在有挂(哔哩哔哩)1、让任何...
透视透视挂!如何下载德普之星辅... 透视透视挂!如何下载德普之星辅助软件(透视)德普之星透视辅助软件是真的吗-都是有挂(哔哩哔哩)1、这...
昨日!aapoker脚本怎么用... 您好,aapoker脚本怎么用这款游戏可以开挂的,确实是有挂的,需要了解加去威信【485275054...
透视了解!hhpoker万能辅... 透视了解!hhpoker万能辅助器(透视)hhpoker透视实战视频-确实真的是有挂(哔哩哔哩)1、...
透视中牌率!hhpoker透视... 透视中牌率!hhpoker透视脚本(透视)hhpoker有没有透视挂-其实真的是有挂(哔哩哔哩)1、...