EF Core 3.1 使用身份验证 = Active Directory 集成 [英] EF Core 3.1 using Authentication=Active Directory Integrated

查看:24
本文介绍了EF Core 3.1 使用身份验证 = Active Directory 集成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

[更新 1]

我可以使用以下连接字符串使其工作

I could make it work using the following connection string

Server=tcp:mydatabaseserver.database.windows.net,1433;Initial Catalog=mydbname

并实现 这篇文章.

这证明 Azure 配置正确,问题出在应用程序的某个地方(可能是缺少包?).

This proves that Azure is correctly configured, and the problem is somewhere in the application (maybe a missing package?).

无论如何,我仍然希望能够更改连接字符串并在 AAD 身份验证和 sql 身份验证之间切换,而无需在应用程序中添加额外的逻辑.

Anyway, I would still like to be able to change the connection string and switch between AAD authentication and sql authentication, without additional logic in the application.

[/更新 1]

我在 Azure WebApp 上使用 EF Core 3.1.4,我想使用分配给应用程序的 Azure AD 身份进行身份验证,但遇到以下异常:

I'm using EF Core 3.1.4 on an Azure WebApp, and I would like to use the Azure AD identity assigned to the application for authentication, but I run into the following exception:

ArgumentException: Invalid value for key 'authentication'.
Microsoft.Data.Common.DbConnectionStringBuilderUtil.ConvertToAuthenticationType(string keyword, object value)

这是连接字符串:

{
    "ConnectionStrings": {
        "Admin": "Server=tcp:mydatabaseserver.database.windows.net,1433;Initial Catalog=mydbname;Authentication=Active Directory Integrated"
    }
}

我使用以下代码初始化上下文:

I initialize the context using the following code:

var connectionString = this.Configuration.GetConnectionString("Admin");
services.AddDbContext<NetCoreDataContext>(builder => builder.UseSqlServer(connectionString));

Microsoft.Azure.Services.AppAuthentication 包也被导入(版本1.5.0)

推荐答案

欢迎来到网络框架/运行时地狱.

Welcome to the Net frameworks/runtimes hell.

目前 NetCore 应用不支持 ActiveDirectoryIntegratedActiveDirectoryInteractive身份验证选项.

Currently ActiveDirectoryIntegrated and ActiveDirectoryInteractiveauthentication options are not supported for NetCore apps.

原因是从 v3.0 开始,EF Core 使用 Microsoft.Data.SqlClient 而不是 System.Data.SqlClient.以及目前最新版本的 Microsoft.Data.SqlClient(也预览版)仅对 NET Framework 支持这两个选项.

The reason is that starting with v3.0, EF Core uses Microsoft.Data.SqlClient instead of System.Data.SqlClient. And the most recent at this time version of Microsoft.Data.SqlClient (also the preview versions) supports these two options only for NET Framework.

您可以在他们的问题跟踪器中看到类似的问题 为什么 .Net Core 的 SqlClient 不允许身份验证方法Active Directory 交互"?#374,以及 SqlAuthenticationMethod 枚举 - ActiveDirectoryIntegrated(重点是我的):

You can see similar question in their issue tracker Why does SqlClient for .Net Core not allow an authentication method 'Active Directory Interactive'? #374, as well as the documentation of the SqlAuthenticationMethod enum - ActiveDirectoryIntegrated (emphasis is mine):

身份验证方法使用 Active Directory 集成.使用集成的 Active Directory 连接到使用集成 Windows 身份验证的 SQL 数据库.仅适用于 .NET Framework 应用程序.

The authentication method uses Active Directory Integrated. Use Active Directory Integrated to connect to a SQL Database using integrated Windows authentication. Available for .NET Framework applications only.

话虽如此,请使用 Authentication 解决方法,或等待此选项最终为 Net Core 实现.

With that being said, use the Authentication workaround, or wait this option to be eventually implemented for Net Core.

这篇关于EF Core 3.1 使用身份验证 = Active Directory 集成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆