相关疑难解决方法(0)

Asp.net Identity使用密码和Azure Active Directory身份验证

我正在使用Asp.net Identity(OWIN)构建ASP.NET MVC 5网站,并希望支持传统的用户名/密码身份验证以及针对Azure Active Directory的身份验证.此应用程序不需要针对Microsoft ID(Live ID),Facebook,Twitter或任何其他外部提供程序进行身份验证.我找到的最接近的SO问题是:如何在ASP.NET MVC上执行Azure Active Directory单点登录和表单身份验证

我查看了使用"个人用户帐户"选项以及VS 2015中的"工作和学校帐户"选项创建项目时创建的示例.我的身份验证工作正常; 只有当我尝试将它们结合起来时,我才遇到问题.

在我的Startup_Auth.cs文件中,我正在配置OWIN,如下所示:

    public void ConfigureAuth(IAppBuilder app)
    {

        app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);

        //app.UseCookieAuthentication(new CookieAuthenticationOptions { });

        app.UseCookieAuthentication(new CookieAuthenticationOptions
        {
            AuthenticationType = DefaultAuthenticationTypes.ExternalCookie,
            LoginPath = new PathString("/account/sign-in")
        });

        app.UseOpenIdConnectAuthentication(
            new OpenIdConnectAuthenticationOptions
            {
                ClientId = clientId,
                Authority = authority,
                TokenValidationParameters = new System.IdentityModel.Tokens.TokenValidationParameters
                {
                    ValidateIssuer = false,
                },
                Notifications = new OpenIdConnectAuthenticationNotifications()
                {
                    SecurityTokenValidated = (context) => 
                    {
                        return Task.FromResult(0);
                    },
                    AuthorizationCodeReceived = (context) =>
                    {
                        return Task.FromResult(0);
                    },
                    AuthenticationFailed = (context) …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-mvc azure asp.net-identity azure-active-directory

15
推荐指数
1
解决办法
4261
查看次数

支持MVC5/ASP.Net Identity 2中的个人用户帐户和组织帐户

我已经创建了一个ASP.Net MVC5应用程序,我已经通过谷歌,Facebook等配置(并且工作正常)个人用户帐户.

我想做的还是支持Azure Active Directory(组织帐户)的身份验证.这将使内部员工能够以管理员身份登录应用程序.

我发现的所有现有信息/指南/文档通常涉及使用其中一个.我如何一起启用它们?

如果需要为每种类型的用户提供单独的登录表单,那么这不是问题.

编辑:

我正在查看Azure Active Directory门户中的应用程序配置,并注意到它们定义了"OAUTH 2.0 AUTHORIZATION ENDPOINT".可以在其中配置MVC5 Startup.Auth.cs来使用它吗?

authentication azure asp.net-identity azure-active-directory asp.net-mvc-5.1

13
推荐指数
1
解决办法
3249
查看次数

是否可以在一个ASP.NET MVC应用程序中同时具有Azure AD和个人帐户身份验证?

通过在Startup.Auth.cs文件中执行此操作,我有点成功

  // Configure the db context and user manager to use a single instance per request
        app.CreatePerOwinContext(ApplicationDbContext.Create);
        app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create);
        app.Properties["Microsoft.Owin.Security.Constants.DefaultSignInAsAuthenticationType"] = "ExternalCookie";

        // Configure the sign in cookie
        app.UseCookieAuthentication(new CookieAuthenticationOptions
        {
            AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
             Provider = new CookieAuthenticationProvider
            {
                OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>(
                    validateInterval: TimeSpan.FromMinutes(30),
                    regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
            }
        });

        app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);

        app.UseOpenIdConnectAuthentication(
          new OpenIdConnectAuthenticationOptions
          {
              ClientId = clientId,
              Authority = authority,
              PostLogoutRedirectUri = postLogoutRedirectUri
          });
Run Code Online (Sandbox Code Playgroud)

我遇到的挑战是,当用户退出时,尝试点击非登录页面,例如http:// mywebsite/users/management而不是http:// mywebsite/account/login,应用程序重定向到Azure自动AD登录页面,这是不对的.因为可能有用户根本没有Azure AD帐户.即使我们在AD登录页面中提供了正确的用户ID和密码并单击登录,它仍然会在http://login.windows.net中的不同网址之间重定向,并且根本不会访问我们的网站.

这是注销码 -

           AuthenticationManager.SignOut(new string[] …
Run Code Online (Sandbox Code Playgroud)

c# asp.net authentication asp.net-mvc azure

10
推荐指数
1
解决办法
3275
查看次数