microsoft / artifacts-credprovider

The Azure Artifacts Credential Provider enables dotnet, NuGet.exe, and MSBuild to interactively acquire credentials for Azure Artifacts feeds.
MIT License
766 stars 706 forks source link

Create Microsoft.Artifacts.Authentication package #388

Closed JohnSchmeichel closed 1 year ago

JohnSchmeichel commented 1 year ago

Proposed changes to pull the MSAL related types into their own project and deliver as an extension to MSAL. Design and implementation are a work in progress to collect feedback on the approach and API design.

Example usage of to create a PublicClientApplication with recommended settings and defaults for Azure Artifacts and enumerate providers:

var app = AzureArtifacts.CreateDefaultBuilder(authority)
    .WithBroker(true, logger)
    .WithLogging((LogLevel level, string message, bool containsPii) =>
    {
        // Application specific logging
    })
    .Build();

// Can use MsalTokenProviders which works for most cases, or compose the token providers manually
var providers = MsalTokenProviders.Get(app, logger);

var tokenRequest = new TokenRequest("https://pkgs.dev.azure.com/org")
{
    IsInteractive = true
};

foreach (var provider in providers)
{
    if (!provider.CanGetToken(tokenRequest))
        continue;

    var result = await provider.GetTokenAsync(tokenRequest);
}
  1. Uses and extends the MSAL token types, and not trying to be a wrapper around them. No plans to support more token authentication libraries in the future.
  2. Uses Microsoft.Extensions.Logging as the logging infrastructure, and adaptors will be created where necessary to interface with client tooling.
  3. All settings and defaults are pulled out onto TokenRequest, or are composable using extension methods.