Add Entra authentication to the Helix API client - #17366
Conversation
Use environment-specific scopes and Azure.Core's expiry-aware Bearer policy for TokenCredential callers while preserving PAT overloads during migration. AB#12269 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: e890b71a-c1aa-416c-a15c-be8da9fdd9b4
There was a problem hiding this comment.
Pull request overview
Adds Entra ID (AAD) authentication support to the Helix C# API client by introducing scope-aware configuration in HelixApiOptions and new ApiFactory overloads, plus unit tests to validate mode/scope selection.
Changes:
- Introduces
HelixApiAuthenticationModeand exposes selected auth mode + token scopes viaHelixApiOptions, selecting production/staging scopes by host and usingBearerTokenAuthenticationPolicyfor Entra credentials. - Adds
ApiFactory.GetAuthenticated(...)overloads forTokenCredential(including an explicit-scope overload for custom hosts) while keeping PAT-based overloads. - Adds unit tests covering anonymous/PAT/Entra modes and default vs explicit scope behavior.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/Microsoft.DotNet.Helix/Sdk.Tests/Microsoft.DotNet.Helix.Sdk.Tests/Microsoft.DotNet.Helix.Sdk.Tests.csproj | Adds a direct project reference to the Helix client project to support new auth-option tests. |
| src/Microsoft.DotNet.Helix/Sdk.Tests/Microsoft.DotNet.Helix.Sdk.Tests/HelixApiAuthenticationTests.cs | New tests validating auth mode selection and default/explicit scope behavior. |
| src/Microsoft.DotNet.Helix/Client/CSharp/HelixApiOptions.cs | Implements Entra scope selection/exposure and configures expiry-aware bearer token auth policy. |
| src/Microsoft.DotNet.Helix/Client/CSharp/ApiFactory.cs | Adds TokenCredential-based factory overloads for Entra authentication (including explicit-scope support). |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
Reviewers added to this PR: • Matt Mitchell ( mmitche ) — active owner and contributor across the Arcade Helix SDK/client. |
Use distinct Entra factory method names to preserve source compatibility and reject PAT credentials when explicit OAuth scopes are supplied. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: e890b71a-c1aa-416c-a15c-be8da9fdd9b4
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.
Suppressed comments (2)
src/Microsoft.DotNet.Helix/Client/CSharp/HelixApiOptions.cs:37
- The exception message says “Use the PAT-specific HelixApiOptions constructor instead”, but there is no PAT-specific HelixApiOptions overload (the PAT path is HelixApiOptions(Uri, TokenCredential) with a HelixApiTokenCredential, or ApiFactory.GetAuthenticated(...)). This could mislead callers; consider rewording the message to point at the actual constructor/API to use.
throw new ArgumentException(
"Explicit scopes are only supported for Entra credentials. " +
"Use the PAT-specific HelixApiOptions constructor instead.",
nameof(credentials));
src/Microsoft.DotNet.Helix/Client/CSharp/HelixApiOptions.cs:87
- GetDefaultScope accesses baseUri.Host without validating baseUri.IsAbsoluteUri. If a caller passes a relative Uri, this will throw an InvalidOperationException (“operation is not supported for a relative URI”) rather than a clear ArgumentException. Consider checking IsAbsoluteUri up front and throwing an ArgumentException with a helpful message/param name.
private static string GetDefaultScope(Uri baseUri)
{
if (baseUri.Host.Equals("helix.dot.net", StringComparison.OrdinalIgnoreCase))
{
return ProductionScope;
Summary
Validation
Microsoft.DotNet.Helix.Sdk.Testsbuild and test runTracking: https://dev.azure.com/dnceng/internal/_workitems/edit/12269