I am trying to write a C# console app to get my own user attributes (such as businessPhones, displayName, givenName, id, jobTitle, mail, mobilePhone, officeLocation, preferredLanguage, surname, and userPrincipalName) from Azure AD by using an interactive login? Using the standard login Windows that pops up when authenticating to AAD.
I started by doing this but ‘Microsoft.IdentityModel.Clients.ActiveDirectory’ is deprecated.
using Microsoft.IdentityModel.Clients.ActiveDirectory;
using Microsoft.Graph;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
class Program
{
static async Task Main(string[] args)
{
string clientId = "my client ID from app reg";
string authority = "https://login.microsoftonline.com/your-tenant-id";
string resource = "https://graph.microsoft.com";
2
Answers
I tried to amend your code to use an interactive login instead of a Client Secret. But I get the following error. 'MeRequestBuilder' does not contain a definition for 'Request' and no accessible extension method 'Request' accepting a first argument of type 'MeRequestBuilder' could be found (are you missing a using directive or an assembly reference?)
Create an Azure AD application and grant User.Read API permission:
Generate the auth-code by using below endpoint and sign-in with the user account:
You can make use of below code to get the singed in user details:
Modify the code and use the below to get the details you require:
And get response like below:
UPDATED: To make use of Interactive browser credential flow make use of below code: