0
votes

After I authenticate with Azure Graph to get a token, I want to use that token to create a Teams online meeting.

When I create an online meeting in Teams, the response contains an error with status code 501.

How do I create an online meeting?

App flow

  1. Start the app
  2. Make a GET request (https://localhost:43321/api)
  3. GetAsync method is executed
  4. Get token with GetToken method
  5. Create a meeting in Teams "online Meetings"
[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, 8, 10, 13, 12, 0),
            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;
}

The app is registered in azure ad.

"ClientId", "tenantId", "clientSecret" inside GetToken method sets the information of Overview of Azure Portal.

The API setting is the state of the image. enter image description here

1

1 Answers

0
votes

client_credentials flow is not supported for creating online meeting.

You should use auth code flow(require user interaction) or ROPC flow(not recommended by Microsoft due to security).

Please check it.