Skip to content

Instantly share code, notes, and snippets.

Created July 8, 2019 23:02
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Gets auth token
private static async Task<TokenCredentials> GetTokenCredentialsAsync()
var clientCredential = new ClientCredential(_clientId, _clientSecret);
var authContext = new AuthenticationContext($"{_tenantId}");
AuthenticationResult result;
result = await authContext.AcquireTokenAsync("", clientCredential).ConfigureAwait(false);
catch (Exception ex)
Console.WriteLine($"Could not get access token for management api. Exception: {ex.Message}");
throw ex;
if (result == null)
throw new InvalidOperationException("Failed to obtain the JWT token");
TokenCredentials Cred = new TokenCredentials(result.AccessToken);
return Cred;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment