我需要创建架构扩展。如何代表用户使用appid连接azure广告?
代码是:
var authenticationContext = new AuthenticationContext(authString, false);
ClientCredential clientCred = new ClientCredential(clientId, clientSecret);
AuthenticationResult authenticationResult = await authenticationContext.AcquireTokenAsync(resourceId, clientCred);
string token = authenticationResult.AccessToken;
var responseString = String.Empty;
using (var client = new HttpClient())
{
string requestUrl = "https://graph.microsoft.com/beta/schemaExtensions";
string postJson = "{\"id\":\"graphlearn_courses\",\"description\": \"Graph Learn training courses extensions\", \"targetTypes\":[\"Group\"], \"properties\": [{ \"name\": \"courseId\",\"type\": \"Integer\"}, {\"name\": \"courseName\",\"type\": \"String\"}, {\"name\": \"courseType\", \"type\": \"String\"}]}";
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, requestUrl);
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", token);
request.Content = new StringContent(postJson, Encoding.UTF8, "application/json");
Debug.WriteLine(request.ToString());
HttpResponseMessage response = client.SendAsync(request).Result;
responseString = response.Content.ReadAsStringAsync().Result;
}
令牌:
"roles": [
"User.ReadWrite.All",
"Group.Read.All",
"Directory.ReadWrite.All",
"User.Read.All"
],
没有得到:Directory.AccessAsUser.All
个用户凭证:
UserPasswordCredential userCred = new UserPasswordCredential(userId, userPassword);
var authenticationContext = new AuthenticationContext(authString, false);
ClientCredential clientCred = new ClientCredential(clientId, clientSecret);
AuthenticationResult authenticationResult = await authenticationContext.AcquireTokenAsync(resourceId, clientId, userCred);
string token = authenticationResult.AccessToken;
错误:
AADSTS70002: 请求体必须包含以下参数: 'client_secret或client_assertion'
尝试过,获得跟随错误请求主体必须继续ain以下参数: 'client_secret或client_assertion' –