Access MS Graph Shared Calendars with a console application ?

Avadanei, Daniel 21 Reputation points
2022-10-17T09:54:21.36+00:00

I'm trying to acces the calendars that have been shared with a user using MS Graph sdk. I have a web app and the necessary permissions like Calendars.Read given. Using postman I manage to read the calendar of a user using https://login.microsoftonline.com/{app id}/oauth2/v2.0/authorize for authorization and then https://graph.microsoft.com/v1.0/users/{user}/calendar/events for reading calendar events. Everything works fine in postman, but I'm having issues to do the same thing using MSGraph framework. I tried using this example https://learn.microsoft.com/en-us/graph/sdks/choose-authentication-providers?tabs=CS#client-credentials-provider in order to replicate the postman calls in c# but I receive an error saying that

'Code: BadRequest /me request is only valid with delegated authentication flow'

when I used await graphClient.Me.Calendars.Request().GetAsync();

and

Access is denied. Check credentials and try again

when I used await graphClient.Users["example@ssss .com"].Calendars.Request().GetAsync();

From what I have read the first error with delegated authentication flow appears because I'm using application permissions model and I should be using delegated permissions in this context. The issue is that I don't know how to use ms graph library for delegated permissions model. The only examples that I found involves calling API directly, but I need to use the MS Graph library.

Microsoft Security | Microsoft Graph
0 comments No comments

2 answers

Sort by: Most helpful
  1. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.

    4 deleted comments

    Comments have been turned off. Learn more

  2. Vicky Kumar (Mindtree Consulting PVT LTD) 1,161 Reputation points Microsoft Employee
    2022-10-18T07:39:44.003+00:00

    For your error - 'Code: BadRequest /me request is only valid with delegated authentication flow'

    This is as per design, Client credential flow will generate the token on behalf the app itself, so in this scenario, users don't need to sign in first to generate the token stand for the user and then call the api.

    you should not use the /me endpoint, instead you should use /users/{userID}/calendar/getSchedule

    await graphClient.Users["abc@xyz .com"].Calendars.Request().GetAsync()

    For your another error - Access is denied. Check credentials and try again

    251502-image.png

    Please check the docs, to see common access denied issue - https://learn.microsoft.com/en-us/graph/resolve-auth-errors

    Hope this helps ,
    Thanks

    Was this answer helpful?


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.