12:27 PM
0
A: Service Unavailable with Microsoft Graph (client credentials authentication from C# code)

SrideviAs mentioned in this MS Doc, you need to use Delegated permissions that works with delegated flow like interactive flow or authorization code flow etc.. for retrieving messages from personal accounts. Initially, I registered one multi-tenant Entra ID application by adding redirect URI in "Mobile ...

 
Thanks for your explanations which help me a lot. I was trying to figure out how to implement interactive and authorization code flows (still needs to learn lots of things regarding authentication and authorization). With your configurations and code, when I'm redirected to the login popup, I can pick my company account which I don't want to use and if I use my personal one (@outlook.com) I get the error You can't sign in here with a personal account. Use your work or school account instead.
 
Did you change tenantId to common and check whether the app you are using is multi-tenant or not?
 
Yes, I changed the tenantId to common with Accounts in any organizational directory (Any Microsoft Entra ID tenant - Multitenant) and personal Microsoft accounts (e.g. Skype, Xbox). I also tried with a new App Registration with Personal Microsoft accounts only and have the same issue.
 
Could you include that error message by editing your question?
 
Sorry, I'm not sure to understand what you're asking for. Know I only have the following error You can't sign in here with a personal account. Use your work or school account instead which appears in the web browser login prompt.
 
12:27 PM
I want you to include that error snip and your app config images by editing your question
 
12:40 PM
Do you think it is because I don't have a premium Office365 account anymore?
In fact, I don't use Office (Excel, Word, etc.) anymore (except for Outlook for the mails).
 
But if you are getting response in Graph Explorer, you have to get in code too!
When you run like this, are you getting response in Graph Explorer? i.imgur.com/9JiUDuM.png
 
I'm afraid I'll have to use the token from Graph Explorer again which works very well.
 
One last attempt, can you try creating new app registration with supported type as "Accounts in any organizational directory (Any Microsoft Entra ID tenant - Multitenant) and personal Microsoft accounts (e.g. Skype, Xbox)" and add same redirect URI in Mobile and desktop application platform and run again by following my answer?
 
Yes, status code 200 with about 10 mails listed (I'll still need to investigate how to retrieve them for specific folders later on).
 
Can you take screenshot or gif file and add it here to know what and where you are facing error?
 
12:49 PM
What do you mean by "same URI"? Is it "http://localhost"?
 
Yes
 
By the way, I was asked to develop an app at work which deals with user authorization. Unfortunately, it won't be done by myself...
 
Check this gif once which is working fine for me in retrieving personal outlook mail with attachments i.sstatic.net/jP5VKrFd.gif
 
I just created a new app registration an followed your configuration, but still get the same error; similar to what it is shown here techcommunity.microsoft.com/t5/microsoft-forms/… (2nd or 3rd screenshot).
Apparently, it is a quite common issue..
 
1:04 PM
Could you check your app registration's Manifest file and find what value signInAudience has?
 
I'm sorry I don't even have a manifest in my app...
 
It will be here like this i.imgur.com/leCA2RR.png
 
OK, I thought that you mean a manifest in the C# app.. By the way, when I log to Microsoft EntraId both my work account (from my company) and my personal one are listed.
 
In the scope, try passing only Mail.Read
var scopes = new[] { "Mail.Read" };
 
Yes, I have AzureADandPersonalMicrosoftAccount specified.
 
1:12 PM
In API permissions, you added Mail.Read permission and granted consent right?
 
Yes, User.Read and Mail.Read with Admin consent and granted status
 
Did you try running code with var scopes = new[] { "Mail.Read" };?
 
You know what? You're are a STAR. It seems that changing the scope resolves the issue!!!
 
Ohh Finallyy! Glad to know issue is resolved :)
Please consider accepting the answer by clicking the checkmark beside it and upvote if it's helpful for you in any way.
 
Yes, definitely! But will I have to sign-in via the prompt every time?
 
1:19 PM
Yes, you need to sign in every time when you are using interactive flow.
 
Can you also tell me if I accepted and upvoted the answer correctly?
 
Yes, u did it right! Thank you :)
 
OK, I'll keep learning and see if there are other ways to avoid signing-in later on but the time being it is perfectly fine!