Skip to content

Instantly share code, notes, and snippets.

@xximjasonxx
Created July 9, 2020 01:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xximjasonxx/9054b3493b8d39e3fbf3c7ab6072acd6 to your computer and use it in GitHub Desktop.
Save xximjasonxx/9054b3493b8d39e3fbf3c7ab6072acd6 to your computer and use it in GitHub Desktop.
using (var client = new HttpClient())
{
client.BaseAddress = new System.Uri("https://<your tenant>.auth0.com/");
var response = await client.PostAsync("oauth/token", new FormUrlEncodedContent(
new Dictionary<string, string>
{
{ "grant_type", "client_credentials" },
{ "client_id", "<client_id>" },
{ "client_secret", "<client_secret>" },
{ "audience", "https://<your tenant>.auth0.com/api/v2/" }
}
));
var content = await response.Content.ReadAsStringAsync();
var jsonResult = JObject.Parse(content);
var mgmtToken = jsonResult["access_token"].Value<string>();
using (var mgmtClient = new ManagementApiClient(mgmtToken, new System.Uri("https://<your tenant>.auth0.com/api/v2")))
{
return await mgmtClient.Users.GetAsync(userId);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment