Auth0 Home Blog Docs

How to use the .NET SDK to get an access token for the management API?



I’m using the following code to try to get an access token for using the management API:

string auth0Domain = "";
var auth0AuthenticationClient = new AuthenticationApiClient(
    new Uri(String.Format("https://{0}", auth0Domain)));
var tokenRequest = new ClientCredentialsTokenRequest()
        ClientId = "my client id",
        ClientSecret = "my client secret",
        Audience = String.Format("https://{0}/api/v2", auth0Domain),
var tokenResponse = 
    await auth0AuthenticationClient.GetTokenAsync(tokenRequest);

However I get the following error:

Client is not authorized to access
You might probably want to create a
"client-grant" associated to this API.

I googled that error and found this question:

However I have already done all of those steps, ie created a non-interactive client, authorized the client for the management API, and configured some scopes.

Any ideas what else I could be missing?



You are requesting a token for the API with identifier (audience) https:/

The Management API identifier is https:/ - notice the trailing slash. Please amend your audience to reflect this.


Awesome, thanks @prashant, that fixed it! :slight_smile: