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

“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

- 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 (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.

- 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.

- 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!”

- 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

- 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

- 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

- 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

- 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.

- 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

- Find Our Certificate: We go back to Certificate Manager, find our certificate, and double-click it.

- 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.

- 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.

- 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

- Find the “API permissions” page in your app registration.
Add Needed Permissions

- 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 must be logged in to post a comment.