SQL Server: consider adding first class support for SqlConnection.AccessToken for AAD

Open
#13,261 56 comments 27 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
25/100
Issue type
Feature
Clarity
Needs clarification
Activity status
Stale
Tech stack
azure, csharp

Research direction

Start with the SQL Server provider's UseSqlServer configuration and the AddDbContext pattern described in the issue. Investigate whether access tokens are obtained asynchronously and whether they can be cached, then define the required first-class API and its safe behavior. Done means the API design supports Azure AD authentication without requiring manual SqlConnection creation.

Written by the indexing model from the issue text.

Description

area-dbcontext blocked needs-design

SqlConnection.AccessToken is added to SqlClient for .NET Core in 2.2 to enable Azure Active Directory Authentication.

Although it is already possible to use the feature with the current APIs in EF Core and our SQL Server provider, it requires creating the SqlConnection object and passing it to UseSqlServer (or somehow setting the access token just before the connection object is ever opened).

That pattern is a bit more convoluted and forces you to deviate from the common pattern in ASP.NET Core applications that uses AddDbContext with a simple connection string.

This issue is about making this more first-class, for example, by enabling passing the AccessToken in the UseSqlServer call as a separate piece of configuration from the connection string.

We should understand the common patterns to use the feature safely to decide what APIs we actually need:

  • Is the access token obtained using async API?
  • Can we assume that the authentication token will be obtained only once and then can be cached?
Dominant language
C#
Stars
14.8k
Forks
3.4k
Avg merge
2d 5h
Merged PRs (30d)
134

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from dotnet/efcore

All issues in dotnet/efcore

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.