Auth0 Home Blog Docs

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

.net
management-api
access-token

#1

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:
https://auth0.com/docs/api/v2#!/Client_Grants/post_client_grants

I googled that error and found this question:

https://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


#2

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.


#3

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


#4