我们可以在 ASP.NET MVC 中使用多种身份验证方法吗

问题描述 投票:0回答:0

我正在做一个 ASP.NET MVC 项目,我们已经实现了用户名/密码身份验证。我们正在尝试向项目添加 SAML 身份验证 (Azure AD)。那可能吗?这两种认证方式可以在同一个项目中共存吗?如果是这样,我该如何实施?

这是我现在的创业班:

Imports Microsoft.AspNet.Identity
Imports Microsoft.AspNet.Identity.EntityFramework
Imports Microsoft.AspNet.Identity.Owin
Imports Microsoft.Owin
Imports System.Web.Configuration
Imports Owin
Imports Microsoft.Owin.Security.Cookies

Public Class Startup 
Public Sub Configuration(app As IAppBuilder)

Dim timeoutKey As Integer = Integer.Parse(WebConfigurationManager.AppSettings("timeOut"))

app.CreatePerOwinContext(Function() New Entities())
app.CreatePerOwinContext(Of UserManager)(Function() UserManager.Create(Nothing, HttpContext.Current.GetOwinContext())) 'CTNOTE: I had to modify this... Keep an eye on it.
app.CreatePerOwinContext(Of RoleManager(Of Role))(Function(options, context) New RoleManager(Of Role)(New RoleStore(Of Role)(context.Get(Of Entities)())))


app.UseCookieAuthentication(New CookieAuthenticationOptions() With {
    .AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
    .Provider = New CookieAuthenticationProvider() With {
        .OnResponseSignIn = Sub(context)
                              context.Properties.AllowRefresh = True
                              context.Properties.ExpiresUtc = DateTimeOffset.UtcNow.AddMinutes(timeoutKey)
                            End Sub
    },
    .SlidingExpiration = True,
    .CookieName = WebConfigurationManager.AppSettings("cookie"),
    .CookieHttpOnly = True,
    .CookieSecure = CookieSecureOption.Always,
    .CookieSameSite = SameSiteMode.Lax,
    .ExpireTimeSpan = TimeSpan.FromMinutes(timeoutKey),
    .LoginPath = New PathString("default"),
    .LogoutPath = New PathString("default"),
    .ReturnUrlParameter = "ReturnTo"}
    )
End Sub
End Class

我正在关注此 SSO 集成教程:https://learn.microsoft.com/en-us/azure/active-directory/saas-apps/saml-toolkit-tutorial,但我不知道如何使其与我在项目中已有的表单身份验证方法一起使用。

项目不是 ASP.NET Core

asp.net-mvc authentication single-sign-on saml
© www.soinside.com 2019 - 2024. All rights reserved.