Skip to content

mgmt: Refactor to Support custom Token Provider#926

Merged
kailash-b merged 1 commit into
v8from
custom-wrapper
Mar 2, 2026
Merged

mgmt: Refactor to Support custom Token Provider#926
kailash-b merged 1 commit into
v8from
custom-wrapper

Conversation

@kailash-b
Copy link
Copy Markdown
Contributor

Changes

Refactors the ManagementClient wrapper to introduce a first-class ITokenProvider abstraction for token acquisition.

New classes:

  • ITokenProvider — interface with a single GetTokenAsync(CancellationToken) method; the contract for all token providers.
  • ClientCredentialsTokenProvider — implements ITokenProvider and IDisposable. Automatically acquires and caches tokens via the OAuth 2.0 client credentials grant. Tokens are cached until expiry with a 10-second leeway and refreshed lazily on the next call. Thread-safe via double-checked locking (SemaphoreSlim + Volatile/Interlocked).
  • DelegateTokenProvider — implements ITokenProvider. A lightweight wrapper that invokes a user-supplied Func<CancellationToken, Task<string>> on every call. No caching. Intended for callers who manage their own token lifecycle (e.g. secret managers, external caches).

ManagementClientOptions now accepts a TokenProvider property instead of raw credentials, making the token acquisition strategy explicit and swappable.

Usage:

// Automatic token management
var client = new ManagementClient(new ManagementClientOptions
{
    Domain = "your-tenant.auth0.com",
    TokenProvider = new ClientCredentialsTokenProvider(
        "your-tenant.auth0.com", clientId, clientSecret)
});

// Custom token source
var client = new ManagementClient(new ManagementClientOptions
{
    Domain = "your-tenant.auth0.com",
    TokenProvider = new DelegateTokenProvider(ct => secretManager.GetTokenAsync(ct))
});

References

N/A

Testing

  • This change adds unit test coverage

  • This change adds integration test coverage

  • This change has been tested on the latest version of the platform/language or why not

Checklist

@kailash-b kailash-b requested a review from a team as a code owner February 26, 2026 06:50
@codecov
Copy link
Copy Markdown

codecov Bot commented Feb 26, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 33.88%. Comparing base (c9630d0) to head (480f72a).
⚠️ Report is 2 commits behind head on v8.

Additional details and impacted files
@@           Coverage Diff           @@
##               v8     #926   +/-   ##
=======================================
  Coverage   33.87%   33.88%           
=======================================
  Files        1977     1978    +1     
  Lines       72861    72858    -3     
  Branches     4273     4271    -2     
=======================================
+ Hits        24685    24691    +6     
+ Misses      46952    46947    -5     
+ Partials     1224     1220    -4     
Flag Coverage Δ
authIntTests 4.06% <43.18%> (+0.03%) ⬆️
mgmtIntTests 32.17% <100.00%> (+0.19%) ⬆️
unittests 0.43% <0.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ 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.

@kailash-b kailash-b changed the title Refactor wrapper to extend TokenProvider mgmt: Refactor to Support custom Token Provider Feb 26, 2026
Comment thread src/Auth0.ManagementApi/Wrapper/ManagementClient.cs Outdated
Comment thread src/Auth0.ManagementApi/Wrapper/ManagementClient.cs
@kailash-b kailash-b merged commit 7d2fb8e into v8 Mar 2, 2026
8 checks passed
@kailash-b kailash-b deleted the custom-wrapper branch March 2, 2026 07:22
@kailash-b kailash-b mentioned this pull request Apr 2, 2026
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.

2 participants