DEV Community

Cover image for Hackathon - Hack Together: Microsoft Graph and .NET πŸ¦’ - Day 03
Emanuele Bartolesi
Emanuele Bartolesi

Posted on

1

Hackathon - Hack Together: Microsoft Graph and .NET πŸ¦’ - Day 03

Here we are again, at Day 3 this time.

Today I wrote a lot of backend code. I implemented the authentication with Azure AD and I added the Graph Client SDK.

I don't post the entire code here, but just some hightlights.
First of all I added the Graph Scopes to the appsettings.json file.

{
  "AzureAd": {
    "Authority": "https://login.microsoftonline.com/common",
    "ClientId": "1bc3268c-1570-461d-bf0e-e181ba39415c",
    "ValidateAuthority": true
  },
  "GraphScopes": "Files.Read;Tasks.ReadWrite;User.Read;MailboxSettings.Read;email;offline_access;openid;profile;Calendars.ReadWrite;Mail.Read"
}
Enter fullscreen mode Exit fullscreen mode

In the GraphScopes property I added all the Graph scopes we need in the application (at least, in this moment).

The ClientId comes directly from an Azure App Registration that I have created for this specific project.
You can follow this tutorial, if you are new with this topic.

In the authentication section I added the redirect url for the login callback.

login callback

In the main page, in the code behind, I create a new Graph Client object from the Graph SDK and I retrieve the emails, ordered by received time in descending order.
I also tried to retrieve the Calendar View to retrieve all the items in the calendar for a given date interval but I get an error every time.
I struggled with this exception for 2-3 hours without success.
I will try again tomorrow to solve this problem.

By the way at the moment I can retrieve all items for the UI and the next time I will work on the presentation layers.
I will create some components for each page section (mail, todo, calendar).


Thanks for reading this post, I hope you found it interesting!

Feel free to follow me to get notified when new articles are out πŸ™‚

Sentry image

See why 4M developers consider Sentry, β€œnot bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

Top comments (0)

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

πŸ‘‹ Kindness is contagious

Please leave a ❀️ or a friendly comment on this post if you found it helpful!

Okay