跟进这个问题:
How to do both Azure Active Directory Single Sign On and Forms Authentications on ASP.NET MVC
我尝试在默认 MVC 4 的登录操作上编写简单代码,它同时使用默认表单例份验证和 Azure Active Directory SSO:
public async Task<ActionResult> Login(LoginModel model, string returnUrl)
{
if (ModelState.IsValid && WebSecurity.Login(model.UserName, model.Password, persistCookie: model.RememberMe))
{
return RedirectToLocal(returnUrl);
}
authContext = new AuthenticationContext(authority, new TokenCache());
var result = await authContext.AcquireTokenAsync(resourceId, clientId, new UserCredential(model.UserName, model.Password));
// more code
}
因此,如果正常登录 WebSecurity.Login
不成功,我会尝试使用带有凭据(用户名/密码)的 ADAL.NET 从 AAD 获取 token ,此帖子如下:http://www.cloudidentity.com/blog/2014/07/08/using-adal-net-to-authenticate-users-via-usernamepassword/
运行应用程序时,我从 Azure 收到错误:
AADSTS90027: The client '[ClientId]' and resource '[ResouceId]' identify the same application.
我不确定直接在 MVC 登录操作上使用带有凭据的 ADAL 是否真的有意义。请有人给我一些关于这件事的提示。
最佳答案
ADAL 并不意味着在 Web 应用程序中实现 Web 登录。 ADAL 帮助应用程序获取访问另一个资源的 token :换句话说,它帮助您的应用程序成为 CLIENT。此外,用户名/密码在 Web 应用程序中不可用,因为它只能在 native 应用程序中使用。 为了同时使用 FormsAuth 和 Azure AD,请考虑同时添加 ASP.NET 身份中间件和 OpenId Connect 中间件。 OpenId Connect 中间件是用于通过 Azure AD 实现 Web SSO 的库。
关于c# - 带有 MVC 的 Azure Active Directory,客户端和资源标识相同的应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29698559/