You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
FEAT: Adding authentication module and adding new auth types (#135)
### ADO Work Item Reference
<!-- Insert your ADO Work Item ID below (e.g. AB#37452) -->
>
[AB#37905](https://sqlclientdrivers.visualstudio.com/c6d89619-62de-46a0-8b46-70b92a84d85e/_workitems/edit/37905)
>
[AB#37927](https://sqlclientdrivers.visualstudio.com/c6d89619-62de-46a0-8b46-70b92a84d85e/_workitems/edit/37927)
>
[AB#37926](https://sqlclientdrivers.visualstudio.com/c6d89619-62de-46a0-8b46-70b92a84d85e/_workitems/edit/37926)
-------------------------------------------------------------------
### Summary
This pull request introduces significant enhancements to the
`mssql-python` package, focusing on expanding authentication support and
improving connection string handling. The most notable changes include
adding support for new Azure Active Directory (AAD) authentication
methods, implementing a dedicated authentication module, and integrating
these updates into the connection handling logic.
### Authentication Enhancements:
* **Expanded AAD Authentication Methods**: The documentation
(`README.md`) now reflects support for additional authentication
methods, including `ActiveDirectoryInteractive` (via browser),
`ActiveDirectoryDeviceCode` (for environments without browser access),
and `ActiveDirectoryDefault` (which selects the best method based on the
environment). Notes were added to clarify usage and constraints for
these methods.
* **New `auth.py` Module**: Introduced a dedicated module
(`mssql_python/auth.py`) to handle AAD authentication. This module
includes:
- Support for `DefaultAzureCredential`, `DeviceCodeCredential`, and
`InteractiveBrowserCredential` for token retrieval.
- Utility functions for processing connection string parameters,
removing sensitive data, and generating SQL Server-compatible token
structures.
### Connection Handling Updates:
* **Integration of Authentication Logic**: The
`process_connection_string` function from the new `auth.py` module was
integrated into the connection initialization process in
`mssql_python/connection.py`. If the connection string specifies an AAD
authentication type, it is processed to remove sensitive parameters and
include the appropriate authentication token in `attrs_before`.
* **Import Update**: The `process_connection_string` function was
imported into `mssql_python/connection.py` to enable the integration of
the new authentication logic.
---------
Co-authored-by: Jahnvi Thakkar <jathakkar@microsoft.com>
Co-authored-by: Gaurav Sharma <sharmag@microsoft.com>
Copy file name to clipboardExpand all lines: README.md
+8-2Lines changed: 8 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -48,17 +48,23 @@ By adhering to the DB API 2.0 specification, the mssql-python module ensures com
48
48
49
49
### Support for Microsoft Entra ID Authentication
50
50
51
-
The Microsoft mssql-python driver enables Python applications to connect to Microsoft SQL Server, Azure SQL Database, or Azure SQL Managed Instance using Microsoft Entra ID identities. It supports various authentication methods, including username and password, Microsoft Entra managed identity, and Integrated Windows Authentication in a federated, domain-joined environment. Additionally, the driver supports Microsoft Entra interactive authentication and Microsoft Entra managed identity authentication for both system-assigned and user-assigned managed identities.
51
+
The Microsoft mssql-python driver enables Python applications to connect to Microsoft SQL Server, Azure SQL Database, or Azure SQL Managed Instance using Microsoft Entra ID identities. It supports a variety of authentication methods, including username and password, Microsoft Entra managed identity (system-assigned and user-assigned), Integrated Windows Authentication in a federated, domain-joined environment, interactive authentication via browser, device code flow for environments without browser access, and the default authentication method based on environment and configuration. This flexibility allows developers to choose the most suitable authentication approach for their deployment scenario.
52
52
53
53
EntraID authentication is now fully supported on MacOS and Linux but with certain limitations as mentioned in the table:
54
54
55
55
| Authentication Method | Windows Support | macOS/Linux Support | Notes |
| ActiveDirectoryInteractive | ✅ Yes |❌ No|Only works on Windows|
58
+
| ActiveDirectoryInteractive | ✅ Yes |✅ Yes|Interactive login via browser; requires user interaction|
59
59
| ActiveDirectoryMSI (Managed Identity) | ✅ Yes | ✅ Yes | For Azure VMs/containers with managed identity |
60
60
| ActiveDirectoryServicePrincipal | ✅ Yes | ✅ Yes | Use client ID and secret or certificate |
61
61
| ActiveDirectoryIntegrated | ✅ Yes | ❌ No | Only works on Windows (requires Kerberos/SSPI) |
62
+
| ActiveDirectoryDeviceCode | ✅ Yes | ✅ Yes | Device code flow for authentication; suitable for environments without browser access |
63
+
| ActiveDirectoryDefault | ✅ Yes | ✅ Yes | Uses default authentication method based on environment and configuration |
64
+
65
+
**NOTE**: For using Access Token, the connection string *must not* contain `UID`, `PWD`, `Authentication`, or `Trusted_Connection` keywords.
66
+
67
+
**NOTE**: For using ActiveDirectoryDeviceCode, make sure to specify a `Connect Timeout` that provides enough time to go through the device code flow authentication process.
0 commit comments