问题描述
我通过Azure Graph进行身份验证以获取令牌后,我想使用该令牌创建Teams在线会议。
当我在Teams中创建在线会议时,响应中包含状态码501的错误。
如何创建在线会议?
应用流程
[Route("api")]
[ApiController]
public class ApiController : ControllerBase
{
[HttpGet]
public async Task<ContentResult> GetAsync()
{
var result = GetToken();
string accesstoken = result.Result.access_token;
var httpClient = new WebApp_OpenIDConnect_DotNet.Services.HttpClient();
var meetingData = new MeetingData
{
StartDateTime = new DateTime(2020,8,10,12,57,0),EndDateTime = new DateTime(2020,13,Subject = "meeting"
};
string json = JsonConvert.SerializeObject(meetingData,Formatting.Indented);
(var res,var statusCode) = await httpClient.PostHttpContentWithToken("me/onlineMeetings",accesstoken,json);
var deserialized = JsonConvert.DeserializeObject<MeetingData>(res);
return Content(res);
}
}
private async Task<AccesstokenClass> GetToken()
{
string tokenUrl = "https://login.microsoftonline.com/tenantId/oauth2/v2.0/token";
var tokenRequest = new HttpRequestMessage(HttpMethod.Post,tokenUrl);
tokenRequest.Content = new FormUrlEncodedContent(new Dictionary<string,string>
{
["grant_type"] = "client_credentials",["client_id"] = "clientId",["client_secret"] = "clientSecret",["scope"] = "https://graph.microsoft.com/.default"
});
var results = new AccesstokenClass();
var client = new System.Net.Http.HttpClient();
var tokenResponse = await client.SendAsync(tokenRequest);
var json = await tokenResponse.Content.ReadAsstringAsync();
results = JsonConvert.DeserializeObject<AccesstokenClass>(json);
return results;
}
该应用已在天蓝色广告中注册。
GetToken方法中的“ ClientId”,“ tenantId”,“ clientSecret”设置Azure门户概述的信息。