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

查看:116
本文介绍了使用身份验证的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.

[/ Update 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

推荐答案

欢迎使用Net框架/运行时hell 。

Welcome to the Net frameworks/runtimes hell.

当前 ActiveDirectoryIntegrated ActiveDirectoryInteractive 身份验证选项尚不可用。

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

原因是从EF Core v3.0开始,使用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.

您可以在他们的问题跟踪器中看到类似的问题为什么SqlClient for .Net Core不允许使用身份验证方法 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 Integrated。使用集成的Active Directory通过集成的Windows身份验证连接到SQL数据库。 仅适用于.NET Framework应用程序。

话虽如此,请使用 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天全站免登陆