简体   繁体   English

通过Azure AD ADAL的ASP.NET MVC用户身份验证

[英]ASP.NET MVC User Authentication through Azure AD ADAL

I have an ASP.NET MVC application with Identity 2 authentication that is deployed as an Azure App. 我有一个带有Identity 2身份验证的ASP.NET MVC应用程序,该应用程序被部署为Azure应用程序。 What I am trying to do is use Azure Active Directory Authentication within this App so that users created in the Active Directory (this AD was created within the same subscription of Azure that the App resides on) can authenticate in the App. 我想做的是在此应用程序中使用Azure Active Directory身份验证,以便在Active Directory中创建的用户(此AD在与应用程序驻留的Azure相同的订阅中创建)可以在应用程序中进行身份验证。

With standard Active Directory I would use LDAP(S) protocol for authentication with Domain Controller but in Azure AD I was told to use ADAL library since LDAP protocol is not supported(?). 使用标准的Active Directory,我将使用LDAP(S)协议与域控制器进行身份验证,但是在Azure AD中,由于不支持LDAP协议,被告知使用ADAL库。

I have reviewed a number of implementations of ADAL but I am not sure of the exact flow of actions that need to be performed. 我已经审查了ADAL的许多实现方式,但是我不确定需要执行的确切操作流程。
From the official Github repo I reviewed the AdalDesktopTestApp project and summed up the authentication mechanism as following: 从官方Github上回购我回顾了AdalDesktopTestApp项目,并总结了认证机制如下:

private const string ClientId = "1950a258-227b-4e31-a9cf-717495945fc2";
private const string User = ""; // can also be empty string for testing IWA and U/P
private const string Resource = "https://graph.windows.net";



static void main(string[] args) {
     var context = new AuthenticationContext("https://login.windows.net/common", true, new FileCache());
     RunAppAsync(context).Wait();
}

private static async Task RunAppAsync(AuthenticationContext context) {
    Task<AuthenticationResult> authTask = null;
    authTask = context.AcquireTokenAsync(Resource, ClientId, new UserPasswordCredential(User, Console.ReadLine()));
    await FetchTokenAsync(authTask).ConfigureAwait(false);
}

private static async Task FetchTokenAsync(Task<AuthenticationResult> authTask)
{
    await authTask.ConfigureAwait(false);

    Console.BackgroundColor = ConsoleColor.DarkGreen;
    Console.WriteLine("Token is {0}", authTask.Result.AccessToken);
    Console.ResetColor();
}

What does ClientId become in case of running this code from an Azure App? 如果从Azure应用程序运行此代码,ClientId会变成什么?

Do the Resource variable and AuthenticationContext 's first parameter " https://login.windows.net/common " remain the same in my case? 在我的情况下, Resource变量和AuthenticationContext的第一个参数“ https://login.windows.net/common ”是否保持不变? How do I specify the name of the Active Directory Domain I have created within the Azure? 如何指定在Azure中创建的Active Directory域的名称? Is this the correct flow of actions when authenticating using user accounts that were manually created within the Azure AD? 使用在Azure AD中手动创建的用户帐户进行身份验证时,这是正确的操作流程吗?

Yeah LDAP is not supported. 是的,不支持LDAP。 You need to use OAuth / OpenID Connect, which are made easier with ADAL or MSAL (this is newer and works with the v2 endpoint). 您需要使用OAuth / OpenID Connect(通过ADAL或MSAL可以更轻松地进行操作)(这是更新的版本,可与v2端点一起使用)。

Client id is the id of your registered application in Azure AD. 客户端ID是您在Azure AD中注册的应用程序的ID。 It is also referred to as application id sometimes. 有时也称为应用程序ID。 The Resource identifies what you want to call. 资源标识您要呼叫的内容。 The resource in the sample is the identifier for Azure AD Graph API. 样本中的资源是Azure AD Graph API的标识符。 You'd use eg https://graph.microsoft.com for the newer Microsoft Graph API. 您将使用https://graph.microsoft.com作为更新的Microsoft Graph API。 The access token you acquire is only valid for that API. 您获取的访问令牌仅对该API有效。 Note that MSAL / v2 does not use a resource, instead it uses scopes. 请注意,MSAL / v2不使用资源,而是使用范围。

The URL with "common" is your authority. 具有“ common”的URL是您的权限。 This says what accounts you want to allow to login to your app. 这说明您要允许哪些帐户登录您的应用程序。 Common allows users from any Azure AD tenant to login to your app. Common允许来自任何Azure AD租户的用户登录到您的应用程序。 (your app needs to be multi-tenant then as well) If you want to support only a specific Azure AD tenant, specify it as https://login.microsoftonline.com/your-aad-tenant-id . (然后,您的应用程序也需要是多租户)。如果只想支持特定的Azure AD租户,请将其指定为https://login.microsoftonline.com/your-aad-tenant-id To keep it multi-tenant, set it as https://login.microsoftonline.com/common . 要使其保持多租户状态,请将其设置为https://login.microsoftonline.com/common

You are using the less secure resource owner password credentials grant flow in the app. 您正在应用中使用不太安全的资源所有者密码凭据授予流程。 You should use overloads that pop up a Web browser that allows the user to login properly. 您应该使用重载弹出一个Web浏览器,该浏览器允许用户正确登录。 In your app, users with MFA will be unable to login, for example. 例如,在您的应用中,拥有MFA的用户将无法登录。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ASP.NET MVC 5 中的 Azure AD 身份验证 - Azure AD authentication in ASP.NET MVC 5 ASP.NET / OWIN / ADAL Azure AD身份验证,并定义了应用内角色 - ASP.NET / OWIN/ ADAL Azure AD authentication with in app roles defined and assignment ASP.NET MVC身份-一起使用内部用户和Azure AD身份验证 - ASP.NET MVC Identity - Using internal User and Azure AD Authentication together ASP.NET MVC Core 3.1 中的自定义用户数据与 Azure AD 身份验证? - Custom User data in ASP.NET MVC Core 3.1 with Azure AD Authentication? Azure 应用服务上的 ASP.NET Core MVC Azure AD 身份验证循环 - ASP.NET Core MVC Azure AD Authentication Loop on Azure App Service ASP.NET 内核6:允许Azure AD认证和本地认证 - ASP.NET Core 6 : permit Azure AD authentication and local authentication Azure ASP.NET 核心 MVC WebApp 的 AD 身份验证 - 如何自定义应用程序的 Redirect_URI! 发送 - Azure AD Authentication for ASP.NET Core MVC WebApp - how to customize the Redirect_URI the APPLICATION! sends Visual Studio-ASP.NET MVC 5-默认Azure AD身份验证项目和Microsoft Graph API - Visual Studio - ASP.NET MVC 5 - Default Azure AD Authentication Project and Microsoft Graph API 我们可以申请 ASP.NET Core 3.1 MVC Azure AD 认证使用 HTTP - Can we apply ASP.NET Core 3.1 MVC Azure AD authentication using HTTP 使用Azure AD身份验证的ASP.NET MVC-如何允许用户管理组/角色分配? - ASP.NET MVC using Azure AD authentication — how to allow users to administer group/role assignments?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM