我想在Azure AD中自动创建应用程序并获取Azure AD生成的客户端ID.
是否有PowerShell命令行开关来执行此操作?还有其他方法,比如管理控制台之外的API吗?
你能指点我一个例子吗?
谢谢!
尝试使用Graph API创建应用程序时,我从Azure AD获得403 Forbidden响应:
private static void CreateApplicationViaPost(string tenantId, string clientId, string clientSecret)
{
var authContext = new AuthenticationContext(
string.Format("https://login.windows.net/{0}",
tenantId));
ClientCredential clientCred = new ClientCredential(clientId, clientSecret);
AuthenticationResult result = authContext.AcquireToken(
"https://graph.windows.net",
clientCred);
HttpClient client = new HttpClient();
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", result.AccessToken);
const string json = @"{ displayName: ""My test app"", logoutUrl: ""http://logout.net"", identifierUris: [ ""http://identifier1.com"" ], replyUrls: [ ""http://replyUrl.net"" ] }";
HttpResponseMessage response = client.PostAsync(
string.Format("https://graph.windows.net/{0}/applications?api-version=1.6", tenantId),
new StringContent(json, Encoding.UTF8, "application/json")).Result;
Console.WriteLine(response.ToString());
}
Run Code Online (Sandbox Code Playgroud)
我错过了什么?
编辑: 我在Azure …