Skip to content

Instantly share code, notes, and snippets.

@Ercenk
Last active August 29, 2015 14:20
Show Gist options
  • Save Ercenk/7ad01ec6e1b2110961bb to your computer and use it in GitHub Desktop.
Save Ercenk/7ad01ec6e1b2110961bb to your computer and use it in GitHub Desktop.
Getting a OAuth bearer token for Azure Management APIs
var tenantId = "<tenant>.onmicrosoft.com";
var clientId = "<clientId";
var context = new AuthenticationContext(string.Format("https://login.windows.net/{0}", tenantId));
string user = "<username>@<tenant>.onmicrosoft.com";
string password = Util.ReadLine("Enter password");
var result = context.AcquireTokenAsync("https://management.core.windows.net/", clientId, new UserCredential(user, password)).Result;
"copy the string following this line.".Dump();
result.CreateAuthorizationHeader().Dump();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment