3.73Setting Custom Data for the Access Token Request
Created on Aug 17, 2026~2 min read
When using IHttpAccessTokenProvider to automatically obtain an Access Token, you sometimes need to pass additional dynamic parameters (such as a username, password, client secret, etc.) to the GetAsync method. Through the WithAccessTokenData method, you can preset these parameters when building the request, and the framework automatically copies them into HttpAccessTokenContext.Items for use by GetAsync.
HttpRequestBuilder.Post("https://furion.net/") .SetHttpClientName("myapi") // Optional .WithAccessTokenData("username", "admin") .WithAccessTokenData("password", "123456")Then, in the IHttpAccessTokenProvider.GetAsync method, you can retrieve these values from context.Items:
public async Task<HttpAccessToken?> GetAsync(HttpAccessTokenContext context, CancellationToken cancellationToken){ context.Items.TryGetValue("username", out var username); context.Items.TryGetValue("password", out var password); // Use username and password to obtain a Token...}Note: This method supports multiple calls, and duplicate keys are overwritten by the latest value.