How to generate Azure Active Directory (AAD) authentication token for Graph API without interactive login screen for console/native application?
Details: I am using Graph API to read emails with Azure Active Directory (AAD) with ‘’Delegated’’ permissions.
”Application” permission allows a user to read other mailboxes and there is no admin consent for this approach due to security concerns, so I am using ‘’Delegated’’ permissions.
My console/native application is registered to AAD.
Since AAD generates OAuth Authentication token for a specific account using: 1. Client ID 2. Tenant ID 3. Client Secret (Key/password for the application) 4. Login credentials of a specific account.
I can generate a token using an interactive login screen.
However, I want a mechanism where I can generate AAD token for Graph API (resource) without an interactive login screen within code using C# or.NET
It worked for me with the below code. I am able to recieve the token now with the user credentials and can read the mailbox.
Its seems you are trying to get your token without prompting the sign in page.
Yeah, you can do it using
client_credentials
grant authentication flow withinC#.Net
See the following code snippet:
Access Token Class:
Token Request Method:
Generated Token Response:
Once you have set all of your required credentials you would get the token in response. See the screen shot below:
Update:
To assign dedicated permission for reading mail. Follow the below steps:
See the screen shot: