c# - 带有 MVC 的 Azure Active Directory,客户端和资源标识相同的应用程序

标签 c# asp.net-mvc azure-active-directory

跟进这个问题:

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/

相关文章:

c# - 如何检查我的 C# - MySQL 连接是否成功,或者如果不成功,返回原因?

c# - 无法在 SQL Server 的文本数据类型列中保存超过 43679 个字符

Azure AD 使用 REST API 在应用程序注册中添加应用程序角色

azure - 获取访问 token 时出现错误 AADSTS65001

c# - 实现接口(interface)和访问方法

C# Regex.Replace不区分大小写作为匹配的函数

asp.net-mvc - ASP.NET MVC ActionResult 背后的推理是一个抽象类?

asp.net-mvc - Entity Framework /Glimpse 持续时间差异

asp.net - AntiForgery Token 使用 ASP.NET5 Web API,在 NET46 上没有 System.Web.Helpers

azure - 在 Terraform 中引导 Azure 服务帐户