go-mssqldb: Azure Active Directory Authentication is not supported?
Hi,
I am able to connect to Azure database using SQL authentication but when I use Azure AD credentials I receive TLS handshake error when pinging the database:
Cannot read handshake packet: read tcp: wsarecv: An existing connection was forcibly closed by the remote host.
Connection String:
sqlserver://user:pass@database.windows.net:1433?app+name=MyAppName&database=dbname&encrypt=true&hostNameInCertificate=%2A.database.windows.net&trustservercertificate=true
Is the Azure AD supported or not?
Thanks
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 39 (25 by maintainers)
Thanks! I am so sorry to have to wait on sharing this!
In the docs I had written the description of the connection string changes was:
FedAuth- The federated authentication scheme to use.ActiveDirectoryApplication- authenticates using an Azure Active Directory application client ID and client secret or certificate. Set theusertoclient-ID@tenant-IDand thepasswordto the client secret. If using client certificates, provide the path to the PKCS#12 file containing the certificate and RSA private key in theClientCertPathparameter, and set thepasswordto the value needed to open the PKCS#12 file.ActiveDirectoryMSI- authenticates using the managed service identity (MSI) attached to the VM, or a specific user-assigned identity if a client ID is specified in theuserfield.ActiveDirectoryPassword- authenticates an Azure Active Directory user account in the formuser@domain.comwith a password. This method is not recommended for general use and does not support multi-factor authentication for accounts.I’m not yet familiar with all the flavors of SQL auth and on-prem AD to AAD will need to somehow swap out your Kerberos ticket for an OAuth token. I’m not entirely sure how that works, but you should be able to do it with the code you have as well. Looking at the link you sent, I think your code should look like:
I have just tested this on my branch on Linux, but that should work.