/// <summary> /// Gets the users in a tenant. /// </summary> /// <param name="accessToken">The access token for MS Graph.</param> /// <returns> /// A list of users /// </returns> public async Task <User> GetUserAsync() { try { PrepareAuthenticatedClient(await MsalServiceClient.GetToken("User.Read")); // Using Graph SDK to get users, filtering by active ones and returning just id and userPrincipalName field var UserObjectId = UserHttpContext.HttpContext.User.Claims.Where(c => c.Type == CustomClaimTypes.ObjectId).FirstOrDefault().Value; var user = await graphServiceClient.Me.Request() .Select("id, userPrincipalName, OnPremisesExtensionAttributes") .GetAsync(); return(user); } catch (ServiceException e) { Debug.WriteLine("We could not retrieve the user's list: " + $"{e}"); return(null); } }
public IActionResult Index() { var token = _msalClient.GetToken("api://api.contosocloud.xyz/5c0d2259-c196-42c5-afd4-3ce2d3a01ea2/read"); return(View()); }