-1

I am trying to create online meeting using below code and passing all the details of app registration. Still its returning 404 error.


static string[] scopes = new string[] { "https://graph.microsoft.com/.default" };
    
IConfidentialClientApplication app = ConfidentialClientApplicationBuilder.Create(LaiAppClientID).WithClientSecret(Secret).WithRedirectUri(redirectURI).Build();
    
AuthorizationCodeProvider authProvider = new AuthorizationCodeProvider(app, scopesssss);
    GraphServiceClient graphClient = new GraphServiceClient(authProvider);
    
graphClient = new GraphServiceClient("https://graph.microsoft.com/beta",
                         new DelegateAuthenticationProvider(
                              async (requestMessage) =>
                              {
                                  var token = await app.AcquireTokenForClient(scopesssss).WithAuthority(String.Format("https://login.microsoftonline.com/{0}/oauth2/v2.0/token", tenantID), true).ExecuteAsync();
                                  requestMessage.Headers.Authorization = new AuthenticationHeaderValue("bearer", token.AccessToken);
                               
                              }));
    
var onlineMeeting = new OnlineMeeting
                {
                    StartDateTime = DateTimeOffset.Parse("2021-07-12T21:30:34.2444915+00:00"),
                    EndDateTime = DateTimeOffset.Parse("2021-07-12T22:00:34.2464912+00:00"),
                    Subject = "My First MS Teams Meeting",
                    AudioConferencing= audioConferencing
    
                };
    
var task = Task.Run(async () =>
                {
                    return await graphClient.Me.OnlineMeetings.Request().AddAsync(onlineMeeting);
                    
                });
var d = task.Result;

enter image description here

Joy Wang
  • 39,905
  • 3
  • 30
  • 54
anu
  • 45
  • 1
  • 12

1 Answers1

0

As your code shows, you use the auth code flow to get access token, then create onlineMeeting by MS Graph API. Please see my code, it works well.

string clientId = "<your-client-id>";
string clientSecret = "<your-client-secret>";
string redirectUri = "<your-redirect-url>";
string authority = "https://login.microsoftonline.com/<tenant>";
string authorizationCode = "<the authorization code>";

string[] scopes = new string[] { "https://graph.microsoft.com/.default" };

IConfidentialClientApplication app = ConfidentialClientApplicationBuilder
    .Create(clientId)
    .WithRedirectUri(redirectUri)
    .WithClientSecret(clientSecret)
    .WithAuthority(authority)
    .Build();

AuthorizationCodeProvider auth = new AuthorizationCodeProvider(app, scopes);

GraphServiceClient graphServiceClient = new GraphServiceClient(new DelegateAuthenticationProvider(async (requestMessage) => {

    // Retrieve an access token for Microsoft Graph (gets a fresh token if needed).
    var authResult = await app.AcquireTokenByAuthorizationCode(scopes, authorizationCode).ExecuteAsync();

    // Add the access token in the Authorization header of the API request.
    requestMessage.Headers.Authorization = new AuthenticationHeaderValue("Bearer", authResult.AccessToken);
    
})
);

var onlineMeeting = new OnlineMeeting
{
    StartDateTime = DateTimeOffset.Parse("2021-07-12T21:30:34.2444915+00:00"),
    EndDateTime = DateTimeOffset.Parse("2021-07-12T22:00:34.2464912+00:00"),
    Subject = "My First MS Teams Meeting"
};

await graphServiceClient.Me.OnlineMeetings.Request().AddAsync(onlineMeeting);

Note:

authorizationCode: The auth code flow need to get this code first, then you could obtain the access token for API. See this step, you could request the url by browser and sign in with user, then it will response the code.

permission: To let it work, you need to add the permission(your application -> API permissions -> MS Graph -> Delegated permissions -> OnlineMeetings.ReadWrite) to create onlineMeeting, see here. enter image description here

Reference:

Microsoft Graph API about creating onlineMeeting by C#: link

The sample about using AuthorizationCodeProvider and more details about the code.


UPDATE:

Message: Create online meeting with application permission is only supported in beta.

The API(/v1.0) just supports delegated permission(OnlineMeetings.ReadWrite), not application permission. You could see this in the previous note.

enter image description here

Both the /beta also only supports delegated permission, see:

enter image description here

unknown
  • 6,778
  • 1
  • 5
  • 14
  • Thanx for your reply.I have both permission assigned to App.api permission as below:Now i am getting below err: OnlineMeetings.ReadWrite--Delegated--Read and create user's online meetings-Granted OnlineMeetings.ReadWrite.All--Application-Read and create online meetings Code: NotImplemented Message: Create online meeting with application permission is only supported in beta. – anu Sep 04 '20 at 11:16
  • @sdsUser Have you tried the code in my answer? What is the version of package `Microsoft.Graph`? I used the latest one(3.12.0). – unknown Sep 07 '20 at 01:33
  • The end point [`/v1.0`](https://learn.microsoft.com/en-us/graph/api/resources/onlinemeeting?view=graph-rest-1.0) and [`/beta`](https://learn.microsoft.com/en-us/graph/api/resources/onlinemeeting?view=graph-rest-beta) can also be used to create onlineMeeting, but just `/beta` support **Update onlineMeeting**. If you call the 1.0 API to update onlineMeeting, the error will occur. – unknown Sep 07 '20 at 01:41
  • Yes I tried ur code.I am using Microsoft.Graph version 3.12 using graphServiceClient.Me.OnlineMeetings.Request().AddAsync(onlineMeeting); .Still getting err;Message: Create online meeting with application permission is only supported in beta. Using scope { "https://graph.microsoft.com/.default" };gives above err . and using scope { "https://graph.microsoft.com/beta/.default" } gives err MsalServiceException: AADSTS500011: The resource principal named https://graph.microsoft.com/beta was not found in the tenant named .... – anu Sep 07 '20 at 11:05
  • Hi, @sdsUser. I'm sorry. I missed the "application permission" in your error. The API just supports delegated permission, but not application permission. I add it as **UPDATE** in my reply. – unknown Sep 08 '20 at 02:36
  • Hi @Pamela Peng u want me to remove application read.Write permission and only keep delegated read write permission. – anu Sep 08 '20 at 06:06
  • Yes. As the screenshot in my answer shows, I added only the delegated permission. – unknown Sep 08 '20 at 06:09
  • Hi @Pamela,thanx a lot for replies.I hv removed application permission.plz tell me scope to define?if i use 'https://graph.microsoft.com/.default',"https://graph.microsoft.com/v1.0/.default",https://graph.microsoft.com/beta/.default then getting err "MsalServiceException: AADSTS500011: The resource principal named https://graph.microsoft.com/v1.0 was not found in the tenant named ".also when scope .="https://graph.microsoft.com/OnlineMeetings.ReadWrite" err is "MsalServiceException: AADSTS70011: 'scope' is not valid. The scope https://graph.microsoft.com/OnlineMeetings.ReadWrite is not valid." – anu Sep 08 '20 at 06:26
  • First, both `"https://graph.microsoft.com/v1.0/.default"` and `https://graph.microsoft.com/beta/.default` do not exist. Learn about scope and permission by this [document](https://learn.microsoft.com/en-us/azure/active-directory/develop/v2-permissions-and-consent). To understand easily, learn the [auth code flow](https://learn.microsoft.com/en-us/azure/active-directory/develop/v2-oauth2-auth-code-flow) first. . – unknown Sep 08 '20 at 07:49
  • `https://graph.microsoft.com/OnlineMeetings.ReadWrite` can be used, I'm not sure what's wrong with you, maybe you use [client credentials flow](https://learn.microsoft.com/en-us/azure/active-directory/develop/v2-oauth2-client-creds-grant-flow), the scope of this flow need to be affixed with the .default suffix. But delegate permission doesn't support client credentials flow. – unknown Sep 08 '20 at 07:49
  • Hi, @sdsUser. Have you use this method `app.AcquireTokenByAuthorizationCode(scopes, authorizationCode)` to get access token? I tried with scope `https://graph.microsoft.com/.default` or `https://graph.microsoft.com/OnlineMeetings.ReadWrite`, they all worked well. see https://i.stack.imgur.com/0faae.png – unknown Sep 08 '20 at 09:36
  • yes but i am not able to get authorizationCode programatically bcoz it comes browser and asks for signin so response i am unable to read.if u have any code to get authorizationCode will be helpful. – anu Sep 08 '20 at 10:33
  • Hi @Pamela,I tried using app.AcquireTokenByAuthorizationCode(scopes, authorizationCode) to get access token.and scope https://graph.microsoft.com/OnlineMeetings.ReadWrite suggested by you.I am able to create a meeting successfully.But concern is i am unable to get AuthorizationCode pro-grammatically so i take it manually from browser.so plz proved code to get AuthorizationCode pro-grammatically.Thanx a lot. – anu Sep 08 '20 at 16:08
  • @sdsUser It seems impossible to get AuthorizationCode pro-grammatically. You need a web view to signing in with user, but not just request the url and get code. See the two similar issues: https://stackoverflow.com/a/61002040/13308381 and https://stackoverflow.com/a/59870871/13308381. Could you please raise a new thread for the new question? – unknown Sep 09 '20 at 01:25