如何使用 AAD+MultiFactorAuth 调用 sqlcmd(或 sqlcmd.exe)

How to invoke-sqlcmd (or sqlcmd.exe) with AAD+MultiFactorAuth

我可以找到的所有文档和帮助线程都包含带有 Authentication=ActiveDirectoryIntegrated 的参考连接字符串,以便通过 AAD 集成点击 SQL。如果我使用的是 SSMS,我还可以选择 "Active Directory Universal",如果需要 MultiFactorAuth (MFA),它会给出提示。

我想使用 powershell 来调用-sqlcmd,甚至直接 sqlcmd.exe -- 是否支持 MFA 流程?我还能如何针对启用 AAD 并启用 MFA 的 SQLAzure 实例获取命令行查询?

invoke-sqlcmd : Failed to authenticate the user NT Authority\Anonymous Logon in Active Directory
(Authentication=ActiveDirectoryIntegrated).
Error code 0xCAA2000C; state 10
AADSTS50079: The user is required to use multi-factor authentication.
Trace ID: 54f0cb31-2f0f-4137-b142-b312a6cd441b
Correlation ID: 70204904-576c-4db5-9c3b-6ccd7fe6b409
Timestamp: 2017-02-09 22:56:39Z

我已经看到 https://docs.microsoft.com/en-us/azure/sql-database/sql-database-aad-authentication,并且一切正常,直到应用 MFA,或者当它意识到是时候重新授权和提示时。

如果我有办法缓存凭据,那么 ActiveDirectoryIntegrated 一般都可以工作,我只需要在它决定是时候强制执行 MFA 提示时重新授权和重新缓存我也对此持开放态度.

I want to use powershell to invoke-sqlcmd, or even sqlcmd.exe directly -- do either support an MFA flow?

没有。据我所知,SSMS 是目前唯一通过 Active Directory 通用身份验证为 MFA 启用的工具。(参考 here

如果您对 Azure SQL 数据库有任何想法或建议,可以从 here 提交。

Beginning with version 15.0.1, sqlcmd utility and bcp utility support Active Directory Interactive authentication with MFA.