How can I use the Microsoft Graph SDK in my application?

YAKUB AJIBADE 0 Reputation points
2024-06-01T15:04:55.46+00:00

Good day, I am fairly new to the Microsoft Graph SDK and I require it in this application I am working on.
In a nutshell, I intend to use the API to create a meeting link (For an appointment between Two or more parties, probably just two people). So a lot of people can have different appointments at the same time. I believe you get the idea.
Now, my challenges are

I don't know which of the services I have to use. I believe it should be an online meeting and the platform users can just go on and create meetings when need be but I have been having trouble with the permission. Specifically, "

message='/me request is only valid with delegated authentication flow.'

Now, I am guessing I have to use delegated permission which I believe I am using alreadyUser's image

My guesses are I am using the wrong authentication method but I don't know if I am using the wrong service from the beginning because the onlineMeeting supports only Delegated User permission. Below is a snippet of my code.

I am sorry if this bores you, as I said, I am new to this

credential = ClientSecretCredential(
        tenant_id=tenant_id,
        client_id=client_id,
        client_secret=client_secret)

    
    graph_client = GraphServiceClient(credential, scopes)
 

    request_body = OnlineMeeting(
            # client_secret = client_secret,
            start_date_time = "2019-07-12T14:30:34.2444915-07:00",
            end_date_time = "2019-07-12T15:00:34.2464912-07:00",
            subject = "User Token Meeting",
        )
    print("My reqq_body:", request_body)

    result = await graph_client.me.online_meetings.post(request_body)
Azure API Management
Azure API Management
An Azure service that provides a hybrid, multi-cloud management platform for APIs.
1,939 questions
Microsoft Teams
Microsoft Teams
A Microsoft customizable chat-based workspace.
9,583 questions
Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
11,380 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Sourabh Gupta 800 Reputation points Microsoft Vendor
    2024-06-02T14:53:35.16+00:00

    Hi YAKUB AJIBADE,

    Thanks for reaching out,

    Client credential flow works with application-level permission, when you are acquiring token using Client id and client secret, the me endpoint doesn't make any sense.

    When you use delegated permission and acquire token after user is signed in, in that case token is issued on behalf of a user and me refers to the signed in user.

    With application-level permission, your app act as daemon app which can schedule a meeting on behalf of any user. Since the token is acquired using client secret in your case, your app will not be able to identify the user. so, you should specifically pass the user id as mentioned below.

    However, creating online meeting does not support application-level permissions. To use application permission for this API, tenant administrators must create an application access policy and grant it to a user to authorize the app configured in the policy to create online meetings on behalf of that user (with user ID specified in the request path).

    Refer to this link with more details

    https://video2.skills-academy.com/en-us/graph/api/application-post-onlinemeetings?view=graph-rest-1.0&tabs=http#permissions

    for an example if you want to use client secret credentials and run graph query for a specific user you can refer to this example to read a user's email in python.

    from msgraph import GraphServiceClient
    
    graph_client = GraphServiceClient(credentials, scopes)
    
    
    result = await graph_client.users.by_user_id('user-id').messages.get()
    
    

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".


  2. CarlZhao-MSFT 40,141 Reputation points
    2024-06-03T08:19:26.49+00:00

    Hi @YAKUB AJIBADE

    You should use the delegated context instead of the app-only context.

    # azure.identity
    credential = UsernamePasswordCredential(
        tenant_id=tenant_id,
        client_id=client_id,
        username=username,
        password=password)
    
    graph_client = GraphServiceClient(credential, scopes)
    
    request_body = OnlineMeeting(
    	start_date_time = "2019-07-12T14:30:34.2444915-07:00",
    	end_date_time = "2019-07-12T15:00:34.2464912-07:00",
    	subject = "User Token Meeting",
    )
    
    result = await graph_client.me.online_meetings.post(request_body)
    

    Hope this helps.

    If the reply is helpful, please click Accept Answer and kindly upvote it. If you have additional questions about this answer, please click Comment.