How to get access_token in startup.cs file?

I am trying to implement Auth0.ManagementApi with .net core 2.1 project. Now I want to configure it one time in a startup.cs file instead of creating object everywhere but the issue is it requires accessToken for initialization.

services.AddScoped(provider =>
new ManagementApiClient(“AccessToken”, new Uri(“https://Domain/api/v2”)));

Now I have created a separate class that will get accesstoken.

public async Task GetAccess()
{
var token = await _authenticationApiClient.GetTokenAsync(new ClientCredentialsTokenRequest
{
Audience = “domain”,
ClientId = “clientId”,
ClientSecret = “clientsercret”
});
return token.AccessToken;
}

But I also can’t use this class directly in startup file as it also requires IAuthenticationApiClient to initialize. So how can I achieve what I want? Is ther anyway to pass some sort of delegate?

Hey there!

Sorry for such delay in response! We’re doing our best in providing the best developer support experience out there, but sometimes the number of incoming questions is just too big for our bandwidth. Sorry for such inconvenience!

Do you still require further assistance from us?