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

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

string auth0Domain = "mydomain.au.auth0.com";
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
“https:/mydomain.au.auth0.com/api/v2”.
You might probably want to create a
“client-grant” associated to this API.
See:
Auth0 Management API v2

I googled that error and found this question:

http://community.auth0.com/questions/1626/how-to-generate-a-management-api-token-automatical

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?

Thanks,
Saxon

1 Like

You are requesting a token for the API with identifier (audience) https:/mydomain.au.auth0.com/api/v2.

The Management API identifier is https:/mydomain.au.auth0.com/api/v2/ - notice the trailing slash. Please amend your audience to reflect this.

1 Like

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