404 error while creating Online Meeting using microsoft graph api c# without login into AzureActiveDirectory

I am trying to create Online Meeting using microsoft graph api without login into AzureActiveDirectory with asp.net web application.For this my app has below permissions which are required as per documentation https://docs.microsoft.com/en-us/graph/api/application-post-onlinemeetings?view=graph-rest-1.0&tabs=csharp with client credential auth flow https://docs.microsoft.com/en-us/azure/active-directory/develop/v2-oauth2-client-creds-grant-flow without immediate interaction with a user.I am able to retrive access token successfully as per client-creds-grant-flow.
I tried Micosoft.Graph and Micosoft.Graph.Beta still getting 404 error.

Create online meeting code

  var graphClient = GetAuthenticatedClientCredential();
            var onlineMeeting = new OnlineMeeting
            {
                StartDateTime = DateTimeOffset.Parse("2020-10-01T10:30:34.2444915+00:00"),
                EndDateTime = DateTimeOffset.Parse("2020-10-01T11:00:34.2464912+00:00"),
                Subject = "Create Online Meeting-Without user login to Office 365"
            };

            return await graphClient.Me.OnlineMeetings
                 .Request()
                 .AddAsync(onlineMeeting);

Access Token code
 public static async Task<string> GetUserAccessTokenAsyncByCc()
        {
            IConfidentialClientApplication cca = ConfidentialClientApplicationBuilder.Create(appId)
               .WithTenantId(appTenantId)
               .WithClientSecret(appSecret)
               .Build(); 
            
             string[] scopes1 = new string[] { "https://graph.microsoft.com/.default" };
            //string[] scopes1 = new string[] { "https://graph.microsoft.com/OnlineMeetings.ReadWrite.All" };
            // string[] scopes1 = new string[] { "https://graph.microsoft.com/beta/OnlineMeetings.Read.All" };
            //string[] scopes1 = new string[] { "https://graph.microsoft.com/beta/.default" };
            var result = await cca.AcquireTokenForClient(scopes1).ExecuteAsync();
           
            return result.AccessToken;
        }

and Auth Provider code
public static GraphServiceClient GetAuthenticatedClientCredential()
        {

            DelegateAuthenticationProvider provider = new DelegateAuthenticationProvider(
                     async (requestMessage) =>
                     {
                         string accessToken = await GetUserAccessTokenAsyncByCc();
                         requestMessage.Headers.Authorization = new AuthenticationHeaderValue("bearer", accessToken);
                     });

            GraphServiceClient graphClient = new GraphServiceClient(provider);

            return graphClient;


        }

app permission image
below are the necessary app permission

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

You can only use delegated permissions to create an onlineMeeting, so you must log in as a user, and you cannot use the client credential flow. You need to use the auth code flow to obtain the token.

404 error while creating Online Meeting using microsoft graph api c# without login into AzureActiveDirectory


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x