简体   繁体   English

如何保护Web API和应用程序使用的Azure SQL数据库(Azure AD)

[英]How to secure Azure SQL database used by Web API and Application (Azure AD)

I am currently developing several applications, mostly hosted on Azure : an Excel add-in (Office Apps) that calls an API hosted on Azure, a web application hosted on Azure, and probably other applications later. 我目前正在开发几个应用程序,主要是在Azure上托管:一个Excel加载项(Office应用程序),它调用Azure上托管的API,Azure上托管的Web应用程序,以及稍后可能的其他应用程序。

To authenticate users, I use Azure Active Directory (Azure AD), based on Token authentication for the web API, and OpenID for the web application. 为了对用户进行身份验证,我使用Azure Active Directory(Azure AD),基于Web API的Token身份验证和Web应用程序的OpenID。 Every call to the API or web app is thus authenticated thanks to the Azure AD, so Role-Based Access Control can be implemented in the application layer. 因此,通过Azure AD对API或Web应用程序的每次调用都进行了身份验证,因此可以在应用程序层中实现基于角色的访问控制。

These API/apps are often calling an Azure SQL database and my question is the following : is it possible to use the authenticated user (from Azure AD) to also authenticate the database access ? 这些API /应用程序通常调用Azure SQL数据库,我的问题如下:是否可以使用经过身份验证的用户(来自Azure AD)来验证数据库访问权限?

Currently, database credentials are hardcoded in the connection string (the login is created for the application), but this does not allow strict DB access control rules. 目前,数据库凭据在连接字符串中是硬编码的(为应用程序创建登录名),但这不允许严格的数据库访问控制规则。

Additional information : integrated authentication (using Windows user) is not possible, because Windows login and Azure login are different in my organization : Azure and Windows Active Directories are different. 附加信息:无法使用集成身份验证(使用Windows用户),因为Windows登录和Azure登录在我的组织中有所不同:Azure和Windows Active Directories是不同的。

Thanks a lot for your help. 非常感谢你的帮助。

Yes, Azure SQL Server supports Azure Active Directory authentication. 是的,Azure SQL Server支持Azure Active Directory身份验证。 This article describes how to set it up: https://docs.microsoft.com/en-us/azure/sql-database/sql-database-aad-authentication 本文介绍如何设置它: https//docs.microsoft.com/en-us/azure/sql-database/sql-database-aad-authentication

Your database needs to be V12 for this feature. 您的数据库需要为此功能的V12。 If it is not you can upgrade it to V12. 如果不是,您可以将其升级到V12。

You can then connect to your database with a connectionstring like: 然后,您可以使用以下连接字符串连接到数据库:

    string ConnectionString = @"Data Source=n9lxnyuzhv.database.windows.net; Authentication=Active Directory Integrated; Initial Catalog=testdb;";
    SqlConnection conn = new SqlConnection(ConnectionString);
    conn.Open();

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

相关问题 Azure AD 在 Web API 中使用来自客户端应用程序的令牌 - Azure AD using token from client application in Web API 如何在我的 web 表单应用程序中调用 Azure AD 服务 - how to call Azure AD service in my web form application 如何使用Web应用程序/ WebAPI验证Azure AD中的用户凭据 - How to validate user credentials in Azure AD with Web application / WebAPI 如何在 .Net 核心 Web API 中进行 Azure AD 组授权? - How to do Azure AD groups authorization in .Net core web API? 如何在 WPF 应用程序中使用 Z3A580F142203677F0BC30898 AZFZ 验证 web api - How to authenticate web api in WPF app using Azure AD Azure SQL连接的安全性如何? - How secure is Azure SQL connection? 在 Web API 上验证 Azure AD ID 令牌 - Validating Azure AD ID Token on Web API azure ad users to combobox without azure sql database wpf - azure ad users to combobox without azure sql database wpf Azure AD身份从网站传递到Azure SQL数据库 - Azure AD identity pass through from the website to the azure sql database 如何使用 Azure AD 令牌身份验证从 WPF 应用程序连接到 Azure SQL Server:避免防火墙 - How to Connect to Azure SQL Server from WPF application with Azure AD token autentication : avoid Firewall
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM