问题描述
我在asp.net项目中使用UseOpenIdConnectAuthentication协议连接到我的Azure AD,并且工作正常.
I use in my asp.net project UseOpenIdConnectAuthentication protocol to connect to my Azure AD and it works fine.
今天我也需要使用Asp.net Identity或不同于Azure AD的其他身份验证类型进行身份验证,但是此新身份验证必须与asp.net(相同的项目页面)连接.
Today I need authentication too in Asp.net Identity or other authentication type different from Azure AD, but this new authentication must be connected with asp.net (same project pages).
这是同时进行两种方式的身份验证,文件夹不同,但是在同一项目中.身份验证后,重定向到通用页面.
It's two way authentication at the same time, folders different, but in the same project. After authentication redirect to common page.
你能帮我吗?
Vilela
推荐答案
据我所知,OWIN直接支持多个身份提供者.如果我们配置了多个身份提供者,那么当我们单击登录按钮时,它将使用户能够选择提供给登录的身份,如下图所示:
As far as I know, the OWIN support multiple identity provider directly. If we config the multiple identity provider, when we click the login button, it will enable users to choose the identity provide to login-in like figure below:
以下是供您参考的代码:
And here is the code for your reference:
public void ConfigureAuth(IAppBuilder app)
{
// Configure the db context, user manager and signin manager to use a single instance per request
app.CreatePerOwinContext(ApplicationDbContext.Create);
app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create);
app.CreatePerOwinContext<ApplicationSignInManager>(ApplicationSignInManager.Create);
// Enable the application to use a cookie to store information for the signed in user
// and to use a cookie to temporarily store information about a user logging in with a third party login provider
// Configure the sign in cookie
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Account/Login"),
Provider = new CookieAuthenticationProvider
{
// Enables the application to validate the security stamp when the user logs in.
// This is a security feature which is used when you change a password or add an external login to your account.
OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>(
validateInterval: TimeSpan.FromMinutes(30),
regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
}
});
app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
// Enables the application to temporarily store user information when they are verifying the second factor in the two-factor authentication process.
app.UseTwoFactorSignInCookie(DefaultAuthenticationTypes.TwoFactorCookie, TimeSpan.FromMinutes(5));
// Enables the application to remember the second login verification factor such as phone or email.
// Once you check this option, your second step of verification during the login process will be remembered on the device where you logged in from.
// This is similar to the RememberMe option when you log in.
app.UseTwoFactorRememberBrowserCookie(DefaultAuthenticationTypes.TwoFactorRememberBrowserCookie);
// Uncomment the following lines to enable logging in with third party login providers
//app.UseMicrosoftAccountAuthentication(
// clientId: "",
// clientSecret: "");
//app.UseTwitterAuthentication(
// consumerKey: "",
// consumerSecret: "");
//app.UseFacebookAuthentication(
// appId: "",
// appSecret: "");
//app.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions()
//{
// ClientId = "",
// ClientSecret = ""
//});
app.UseOpenIdConnectAuthentication(
new OpenIdConnectAuthenticationOptions
{
ClientId = "eca61fd9-f491-4f03-a622-90837bbc1711",
Authority = "https://login.microsoftonline.com/adfei.onmicrosoft.com",
});
}
请告诉我是否有帮助.
这篇关于如何将Asp.Net Identity身份验证与Azure AD身份验证连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!