Interface IFortnoxTokenManager
Manages Fortnox access tokens with in-memory caching and thread-safe refresh. Each key represents an independent Fortnox connection (e.g. per company or tenant).
Single-instance only: The in-memory cache is not shared across server instances. If multiple servers use the same Fortnox token, one server's refresh may invalidate another's cached token since refresh tokens are single-use.
public interface IFortnoxTokenManager
Methods
GetAccessTokenAsync(string, Func<Task<TokenData>>, Func<TokenData, Task>)
Returns a valid access token for the given key, refreshing automatically if expired. Uses in-memory caching with per-key locking to prevent concurrent refresh races.
Task<Result<string>> GetAccessTokenAsync(string key, Func<Task<TokenData>> loadToken, Func<TokenData, Task> saveToken)
Parameters
keystringUnique identifier for the Fortnox connection (e.g. company ID).
loadTokenFunc<Task<TokenData>>Delegate to load the current TokenData from persistent storage.
saveTokenFunc<TokenData, Task>Delegate to save the refreshed TokenData to persistent storage.
Returns
- Task<Result<string>>
A Result<TData> containing the access token string on success, or an error on failure.