我对身份验证/授权有疑问.这是我的应用程序设置.应用程序1:使用浏览器提供的ASP.NET MVC应用程序.应用程序2:使用混合移动应用程序提供相同的功能,该应用程序在客户端(app)上使用ionic + angularjs,在服务器端使用ASP.NET Web api.
现在,两个应用程序具有相同的用户群,并且都需要通用的身份验证/授权模块.
我已经通过互联网找到了很多很好的文章,它解释了每个应用程序的认证.我很清楚我需要在OWIN中间件中使用基于令牌的身份验证.
但我不太清楚如何为这两个应用程序实现通用身份验证模块.我计划单独托管ASP.NET MVC应用程序和ASP.NET web api(应用程序的后端部分).如何在两者之间共享通用的身份验证控制器?
如果我分别托管两个,我将为每个单独的AccountController(从MVC的"Controller"派生,并从WebAPI的"ApiController"派生).但不确定,如何合并此控制器以在我的解决方案中使用通用身份验证模块
我是否在正确的方向与托管在一起?或者我需要遵循的任何其他最佳做法?
谢谢
asp.net asp.net-mvc asp.net-membership asp.net-web-api asp.net-identity
我们已经运行了 ASP.NET MVC Web 应用程序,它通过令牌身份验证使用内部用户。这是以 ASP.NET MVC 模板提供的标准方式实现的。
现在我们需要扩展此身份验证模型并允许外部 Azure AD 用户登录到已配置租户的 Web 应用程序。我已经弄清楚了 Azure AD 方面的所有内容。感谢这里的microsoft github 示例
现在个人帐户身份验证和Azure AD独立运行良好。但它不能一起工作。当我将两个中间件插入在一起时,它会出现问题。
这是我的 startup_auth.cs 文件。
public partial class Startup
{
public void ConfigureAuth(IAppBuilder app)
{
app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);
app.CreatePerOwinContext(ApplicationDbContext.Create);
app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create);
app.CreatePerOwinContext<ApplicationSignInManager>(ApplicationSignInManager.Create);
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Account/Login"),
Provider = new CookieAuthenticationProvider
{
OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>(
validateInterval: TimeSpan.FromMinutes(30),
regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
}
});
app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
string ClientId = ConfigurationManager.AppSettings["ida:ClientID"];
string Authority = …Run Code Online (Sandbox Code Playgroud) c# asp.net-mvc azure asp.net-identity azure-active-directory