Skip to content

Add :access_token option for Microsoft Entra ID token login - #616

Open
lucaspearson wants to merge 2 commits into
rails-sqlserver:masterfrom
Faethm-ai:entra-access-token-upstream
Open

lucaspearson wants to merge 2 commits into
rails-sqlserver:masterfrom
Faethm-ai:entra-access-token-upstream

Conversation

@lucaspearson

Copy link
Copy Markdown

Adds an :access_token connection option for Microsoft Entra ID (formerly Azure AD) token login to Azure SQL, Azure Synapse and Microsoft Fabric. Fabric Warehouse accepts no other login. Refs #221, #512.

Change

  • :access_token takes a String, or a callable invoked at connect time so each new connection gets a fresh token.
  • It sets the token with FreeTDS's DBSETLACCESSTOKEN, drops :username and :password, and selects TDS 7.4 (which federated authentication needs) unless :tds_version is given.
  • When FreeTDS lacks DBSETLACCESSTOKEN, using the option raises TinyTds::Error, so a stock FreeTDS build behaves as before for everyone else.
  • README section with an example, and a CHANGELOG entry.

Depends on FreeTDS support: FreeTDS/freetds#754 adds DBSETLACCESSTOKEN (FEDAUTH security token). Fabric also needs FreeTDS/freetds#755 (routing to host\instance). Until those ship, the option compiles out to the error above, so this PR is safe to merge before them. The ports' bundled FreeTDS would need a release that includes them.

Testing:

  • New client test: a proc token is called once, and the login raises TinyTds::Error on the test server, which can't validate a token, and on stock FreeTDS.
  • Used against Microsoft Fabric Warehouse with a patched FreeTDS 1.5 and a workload identity token: connect, queries and reconnects.

Questions for you: should the callable be re-invoked on reconnect inside TinyTDS, or is a new Client per connection (as ActiveRecord does) the expected pattern? And would you rather the error be an ArgumentError?

🤖 Generated with Claude Code

lucaspearson and others added 2 commits December 1, 2026 11:17
Azure SQL, Azure Synapse and Microsoft Fabric accept Microsoft Entra ID
access tokens, and Fabric Warehouse accepts no other login. Add an
:access_token connection option (a String, or a callable invoked at
connect time so each connection gets a fresh token). It sets the token
on the login with DBSETLACCESSTOKEN and drops :username and :password.
It also selects TDS 7.4, which federated authentication requires,
unless :tds_version is given.

This needs FreeTDS with federated authentication support. Without
DBSETLACCESSTOKEN, using the option raises TinyTds::Error.

Refs rails-sqlserver#221, rails-sqlserver#512

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant