A Beginner-Friendly Guide to Using Microsoft Graph API with .NET Core Console App

Empower Our App: Unleashing Microsoft Graph API Superpowers in .NET Core!
Empower Our App: Unleashing Microsoft Graph API Superpowers in .NET Core!

“You only live once, but if you do it right, once is enough.”

Hey there, code wizards! Today, we’re on a mission to supercharge your app by teaming up with Microsoft Graph API and .NET Core. It’s like giving our app a magic wand to talk to Microsoft services. Whether you’re a coding newbie or a tech maestro, we’ve got your back. From setting up in Microsoft’s special place to creating a secret code (certificate), and finally, making our app the superhero of the Microsoft world – it’s going to be a fun ride! Ready to make our app awesome? Let’s get started!

Key Takeaways from this article

In this article:

  • Transform our .NET Core console app into a superhero with Microsoft Graph API.
  • Learn to set up in the Microsoft 365 Admin Center for app management.
  • Create a secure handshake using certificates for enhanced app security.
  • Obtain crucial IDs for your app and organization for seamless integration.
  • Grant permissions to your app, allowing it to perform actions through Microsoft Graph API.
  • Dive into PowerShell to generate a special certificate and install it securely.
  • Configure your Azure AD application by setting up certificates and secrets.
  • Stay tuned for the next article to explore further insights and unleash your app’s full potential!

Discover the riches of Microsoft Graph insights by clicking here. We invite you to enhance our understanding and find valuable tips to complement our journey in leveraging Microsoft Graph API for our .NET Core console app.

Step 1: Setting Up Our App in Azure AD

Getting Started

Dive into the Microsoft 365 Admin Center! Log in with your Microsoft account and gear up for app management superhero-style.
fig. Dive into the Microsoft 365 Admin Center! Log in with your Microsoft account and gear up for app management superhero-style.
  • Go to Microsoft 365 Admin Center:
    • Imagine the Microsoft 365 Admin Center as the superhero headquarters for managing all things Microsoft. To get there, open your web browser and go to admin.microsoft.com.
  • Log in with Your Microsoft Account:
    • Now, it’s time to put on our superhero cape! Log in using your Microsoft account, just like you would when checking your email.

Creating Your App’s Profile

Navigate to Identity in the Microsoft 365 Admin Center: Our app's cozy neighborhood.
fig. Navigate to Identity in the Microsoft 365 Admin Center: Our app’s cozy neighborhood.
  • Navigate to Identity (Formerly Azure Active Directory):
    • Picture the Microsoft 365 admin center as a city full of different places. In the left menu, find and click on “Admin centers.” Now, choose “Identity” – it’s like entering the neighborhood where our app will live.
Unlock Our App's Office: Choose 'App Registrations' to give our app an official spot in the city.
fig. Unlock Our App’s Office: Choose ‘App Registrations’ to give our app an official spot in the city.
  • Select “App Registrations”:
    • Think of “App registrations” as the office where we officially tell Microsoft about our app. It’s like getting our app a spot in the city.
Claiming Our App's Identity: Click '+ New Registration' to officially introduce our app to Microsoft. It's the grand entrance moment!
fig. Claiming Our App’s Identity: Click ‘+ New Registration’ to officially introduce our app to Microsoft. It’s the grand entrance moment!
  • Click “+ New Registration”:
    • Now, we’re about to give our app an official identity! Click the big “+ New registration” button – it’s like saying, “Hey, Microsoft, our app is here!”
Crafting Our App's Identity: Fill in the details, choose a superhero name, decide on access, and hit 'Register' to unveil our creation to the world!
fig. Crafting Our App’s Identity: Fill in the details, choose a superhero name, decide on access, and hit ‘Register’ to unveil our creation to the world!
  • Fill in the Details:
    • This is where we give our app a name – something that makes sense to us. It’s like giving a superhero a cool alias. Decide if only people in our organization can use it or if we want to share it with a broader audience. After that, hit the “Register” button – it’s like officially introducing our superhero to the world!

Setting Up Security

Securing Our App's Realm: Navigate to 'Authentication' – it's like defining our app's secret handshake. Configure settings, set up safe communication spots, and seal the deal by clicking 'Save.'
fig. Securing Our App’s Realm: Navigate to ‘Authentication’ – it’s like defining our app’s secret handshake. Configure settings, set up safe communication spots, and seal the deal by clicking ‘Save.’
  • Go to the “Authentication” section: This is like deciding how people should prove they are who they say they are before using our app.
  • Configure authentication settings: Imagine this as setting up a secret handshake. If our app is a website, we decide where people should go after they log in. For other types of apps, we set up special places where our app can talk to Microsoft safely.
  • Save our changes: Click a button to save our choices. Think of it as locking in our secret handshake.

Getting Important IDs

We head to the 'Overview' page for our app, discover the special IDs – our app's identity and our organization's key. We keep them safe, like the namesakes of our digital realm.
fig. We head to the ‘Overview’ page for our app, discover the special IDs – our app’s identity and our organization’s key. We keep them safe, like the namesakes of our digital realm.
  • Go to our app’s “Overview” page: This is like checking our app’s main information board.
  • Note down the IDs: There are two special ID numbers – one for our app and one for our organization. We keep these safe; they’re like our app’s name and our organization’s name.

Allowing Our App to Do Stuff

Empowering Our App: In 'API permissions,' we specify what our app can do. Add permissions, like telling Microsoft our app's needs. Click 'Grant admin consent' for the official nod.
fig. Empowering Our App: In ‘API permissions,’ we specify what our app can do. Add permissions, like telling Microsoft our app’s needs. Click ‘Grant admin consent’ for the official nod.
  • Go to the “API permissions” section: This is where we say what our app is allowed to do – like read information from Microsoft.
  • Add the necessary permissions: It’s like telling Microsoft, “Hey, our app needs to do these things.” We choose the permissions that make sense for our app.
  • If needed, click a button to make everything official: There’s a button that says “Grant admin consent.” We click it if we need to – it’s like getting permission from the big boss.

Step 2: Creating a Secure Certificate

For safety reasons, we’ll create a special certificate.

Generate a Certificate

We’ll use a tool called PowerShell to make a special certificate.

For a comprehensive guide on PowerShell, check out the tutorial article available here. It’s a valuable resource to enhance your PowerShell skills.

Copy and paste this command:

$cert = New-SelfSignedCertificate -Subject "GraphApiConsoleAppCert" -CertStoreLocation "Cert:\CurrentUser\My" -KeyExportPolicy Exportable -KeySpec Signature

Install the Certificate

Access the Certificate Vault: Uncover the secure realm of Certificate Manager by pressing Windows key + R, typing certmgr.msc, and hitting Enter.
fig. Access the Certificate Vault: Uncover the secure realm of Certificate Manager by pressing Windows key + R, typing certmgr.msc, and hitting Enter.
  • Open Certificate Manager: We open Certificate Manager, which is like a secure vault for certificates. Press the Windows key + R, type certmgr.msc, and hit Enter.
Bringing in Security: Locate our certificate in 'Personal' > 'Certificates,' right-click, choose 'All Tasks,' then 'Import.' Follow the wizard to seamlessly import the certificate.
fig. Bringing in Security: Locate our certificate in ‘Personal’ > ‘Certificates,’ right-click, choose ‘All Tasks,’ then ‘Import.’ Follow the wizard to seamlessly import the certificate.
  • Import the Certificate: We find our certificate under “Personal” > “Certificates.” Right-click, choose “All Tasks,” then “Import.” We follow the wizard to bring in the certificate.

Get the Special Thumbprint

Return to Certificate Manager, pinpoint our certificate, and double-click for a closer look.
fig. Return to Certificate Manager, pinpoint our certificate, and double-click for a closer look.
  • Find Our Certificate: We go back to Certificate Manager, find our certificate, and double-click it.
Capture the Identity: In the 'Details' tab, extract the unique thumbprint – the certificate's distinctive fingerprint. Copy it for secure recognition.
fig. Capture the Identity: In the ‘Details’ tab, extract the unique thumbprint – the certificate’s distinctive fingerprint. Copy it for secure recognition.
  • Copy the Thumbprint: It’s like a unique fingerprint for our certificate. We find it in the “Details” tab and copy it.

Configure Our Azure AD Application

  • Go to Azure Portal: It’s like the control center for our app’s connection to Microsoft services.
  • Open Our App’s Page: We find our app’s registration page in Azure AD.
Elevate Security: Establish Certificates & Secrets by adding a new secret or uploading our certificate. For OpenSSL users, the spotlight is on uploading the certificate file.
fig. Elevate Security: Establish Certificates & Secrets by adding a new secret or uploading our certificate. For OpenSSL users, the spotlight is on uploading the certificate file.
  • Set Up Certificates & Secrets:
    • Add a New Secret or Upload Our Certificate: If we used PowerShell, we create a new client secret with a description. If we used OpenSSL, we upload the certificate file.
Secure Authentication: Update Client Secrets or Certificates & Secrets. For certificates, input the thumbprint for a seamless connection.
fig. Secure Authentication: Update Client Secrets or Certificates & Secrets. For certificates, input the thumbprint for a seamless connection.
  • Configure Authentication:
    • Update Client Secrets or Certificates & Secrets: If we used a client secret, we put in the secret value. If we used a certificate, we put in the thumbprint.

Step 3: Granting Permissions

Now, let’s tell Microsoft that our app is allowed to use Graph API.

Go to API Permissions

Navigate App Powers: Locate the 'API permissions' page in our app registration.
fig. Navigate App Powers: Locate the ‘API permissions’ page in our app registration.
  • Find the “API permissions” page in your app registration.

Add Needed Permissions

Empower Our App: Click 'Add a permission,' choose 'Microsoft Graph,' and select the needed permission, like reading user info. Elevate our app's capabilities!
fig. Empower Our App: Click ‘Add a permission,’ choose ‘Microsoft Graph,’ and select the needed permission, like reading user info. Elevate our app’s capabilities!
  • Click on “Add a permission” and choose “Microsoft Graph.” Pick the permission your app needs, like reading user info.

Admin Consent

  • There’s a button that says “Grant admin consent.” Click on that to make sure everything works smoothly.

Conclusion: Supercharging Our App with Microsoft Graph API

So, there you have it! We’ve taken your .NET Core console app and given it some serious superpowers through Microsoft Graph API. From setting up in the Microsoft 365 superhero hub to creating a special secret handshake (certificate), and finally, getting your app permission to do cool things – it’s been quite a journey.

But guess what? The adventure doesn’t end here! Stay tuned for our next article where we’ll dive even deeper into unleashing the full potential of your app. Get ready for more exciting tips, tricks, and possibilities. Keep coding, and enjoy your app’s new super abilities!

Also get my article updates on my social media handles.

Twitter – https://twitter.com/PrajyotYawalkar?t=oovP0r9FnDtz5nNSJGKO0Q&s=09

LinkedIn – https://www.linkedin.com/in/prajyot-yawalkar-093716224/

Have a wonderful day.

Thanks for reading.

You may also like...

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Discover more from Microsoft 365

Subscribe now to keep reading and get access to the full archive.

Continue reading