Skip to content

docs: add an example of authentication with Azure Container Registry#321

Open
wangxiaoxuan273 wants to merge 12 commits intooras-project:mainfrom
wangxiaoxuan273:credential-provider
Open

docs: add an example of authentication with Azure Container Registry#321
wangxiaoxuan273 wants to merge 12 commits intooras-project:mainfrom
wangxiaoxuan273:credential-provider

Conversation

@wangxiaoxuan273
Copy link
Contributor

@wangxiaoxuan273 wangxiaoxuan273 commented Jan 14, 2026

What this PR does / why we need it

This PR adds an example of using oras-dotnet to authenticate with Azure Container Registry.

Which issue(s) this PR resolves / fixes

Resolves / Fixes #267

Please check the following list

  • Does the affected code have corresponding tests, e.g. unit test, E2E test?
  • Does this change require a documentation update?
  • Does this introduce breaking changes that would require an announcement or bumping the major version?
  • Do all new files have an appropriate license header?

Signed-off-by: Xiaoxuan Wang <wangxiaoxuan119@gmail.com>
@codecov
Copy link

codecov bot commented Jan 14, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.76%. Comparing base (6c439ff) to head (e80f686).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #321   +/-   ##
=======================================
  Coverage   91.76%   91.76%           
=======================================
  Files          64       64           
  Lines        2755     2755           
  Branches      364      364           
=======================================
  Hits         2528     2528           
  Misses        138      138           
  Partials       89       89           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds documentation and example code demonstrating how to authenticate with Azure Container Registry (ACR) using Azure Active Directory (AAD) credentials in the ORAS .NET library.

Changes:

  • Added AzureCredentialProvider class implementing ICredentialProvider for ACR authentication via AAD token exchange
  • Added AzureContainerRegistryAuthentication example demonstrating ACR authentication and cross-registry copy operations
  • Added Azure SDK dependencies (Azure.Containers.ContainerRegistry 1.3.0, Azure.Identity 1.13.1)
  • Updated API documentation index to include the new ACR authentication example

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 12 comments.

Show a summary per file
File Description
tests/OrasProject.Oras.Tests/examples/AzureCredentialProvider.cs Implements ICredentialProvider for ACR authentication using Azure DefaultAzureCredential and AAD token exchange
tests/OrasProject.Oras.Tests/examples/AzureContainerRegistryAuthentication.cs Demonstrates usage of AzureCredentialProvider for cross-registry artifact copy operations
tests/OrasProject.Oras.Tests/OrasProject.Oras.Tests.csproj Adds Azure SDK package references for ACR and Azure Identity support
docs/api/index.md Adds link to the new ACR authentication documentation
docs/api/authenticate_with_ACR.md Documentation page that includes the ACR authentication examples

Signed-off-by: Xiaoxuan Wang <wangxiaoxuan119@gmail.com>
Copilot AI review requested due to automatic review settings February 2, 2026 02:53
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.

private string _aadToken { get; set; } = string.Empty;
private Credential _credential { get; set; } = new Credential();
private DateTimeOffset _tokenExpiry { get; set; } = DateTimeOffset.MinValue;
private ContainerRegistryClient _crClient { get; set; } = new ContainerRegistryClient(new Uri($"https://{host}"));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is cloud specific implementation. I would rename this as _acrClient. _crClient makes its look like a generic client.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

renamed

namespace OrasProject.Oras.Tests.Examples;

// This is an example implementation of AzureCredentialProvider, which
// can be used to authenticate with Azure Container Registry. It implements
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Call out that its using DefaultAzureCredential with the fully qualified type name using cref.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

Signed-off-by: Xiaoxuan Wang <wangxiaoxuan119@gmail.com>
Signed-off-by: Xiaoxuan Wang <wangxiaoxuan119@gmail.com>
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Signed-off-by: Xiaoxuan Wang <wangxiaoxuan119@gmail.com>
Copilot AI review requested due to automatic review settings February 3, 2026 06:04
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 7 changed files in this pull request and generated 1 comment.

Signed-off-by: Xiaoxuan Wang <wangxiaoxuan119@gmail.com>
Signed-off-by: Xiaoxuan Wang <wangxiaoxuan119@gmail.com>
Copilot AI review requested due to automatic review settings February 4, 2026 04:55
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 8 changed files in this pull request and generated 2 comments.


[Push an artifact to a remote repository](./push_artifact.md)

[Authenticate with Azure Container Registry](./authenticate_with_ACR.md) No newline at end of file
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: We might want to put it in a new section called "Cloud-specific Examples" or something like that

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a new section "Cloud-specific Examples"

Signed-off-by: Xiaoxuan Wang <wangxiaoxuan119@gmail.com>
Copilot AI review requested due to automatic review settings February 11, 2026 23:37
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

Comment on lines +49 to +57
if (string.IsNullOrEmpty(hostname))
{
throw new ArgumentException("Hostname cannot be null or empty.", nameof(hostname));
}

if (hostname != Host)
{
throw new ArgumentException($"Hostname '{hostname}' does not match the expected host '{Host}'.", nameof(hostname));
}
Copy link

Copilot AI Feb 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ResolveCredentialAsync throws when hostname doesn’t match Host and compares with a case-sensitive !=. In this codebase, ICredentialProvider implementations return an empty credential for non-matching registries (see SingleRegistryCredentialProvider in src/OrasProject.Oras/Registry/Remote/Auth/SingleRegistryCredentialProvider.cs:75-89), and hostnames should be compared case-insensitively. Consider returning CredentialExtensions.EmptyCredential (or new Credential()) when the hostname doesn’t match, and using string.Equals(..., StringComparison.OrdinalIgnoreCase) (also use IsNullOrWhiteSpace for validation to match existing patterns).

Copilot uses AI. Check for mistakes.
Comment on lines +20 to +27
public static class AzureContainerRegistryAuthentication
{
// This example demonstrates how to use the ICredentialProvider interface to
// authenticate with Azure Container Registry, and perform a copy operation
// between two ACR repositories.
// For production use: Implement proper exception handling, cancellation, and dependency injection.
public static async Task AuthenticateWithAzureContainerRegistry()
{
Copy link

Copilot AI Feb 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an async method but its name doesn’t use the Async suffix, and it also omits a trailing optional CancellationToken parameter. Repo guideline is that async methods should end with Async and CancellationToken should be last with a default value; updating the example keeps it consistent with the rest of the codebase.

Copilot generated this review using guidance from repository custom instructions.
Comment on lines +28 to +29
var httpClient = new HttpClient();

Copy link

Copilot AI Feb 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HttpClient is instantiated but never disposed. Even in examples, prefer using var httpClient = new HttpClient(); (or pass an injected/shared HttpClient) to avoid socket exhaustion and to model the recommended usage pattern.

Copilot uses AI. Check for mistakes.
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.

Add examples for implementing ICredentialProvider

4 participants