Here's the code snippet pulled from Microsoft Learn (https://learn.microsoft.com/en-us/mem/i ... only-auth-)
It seems the line with AuthenticationContext, ClientCredential and SecureClientSecret are depreciated. For example: ClientCredential' is obsolete: 'Use ConfidentialClientApplicationBuilder.WithCertificate or WithClientSecret instead. I cannot get this code snippet to work.
using System.Security;
using System.Configuration;
using Microsoft.Identity.Client;
class IntuneDataWarehouse
{
public static void Main()
{
Console.WriteLine("Intune Datawarehouse Start");
var applicationId = ConfigurationManager.AppSettings["appId"].ToString();
SecureString applicationSecret = ConvertToSecureStr(ConfigurationManager.AppSettings["appKey"].ToString()); // Load as SecureString from configuration file or secret store (i.e. Azure KeyVault)
var tenantDomain = ConfigurationManager.AppSettings["tenantDomain"].ToString();
var msalContext = new AuthenticationContext($"https://login.windows.net/" + tenantDomain + "/oauth2/token");
AuthenticationResult authResult = msalContext.AcquireTokenAsync(
resource: "https://api.manage.microsoft.com/",
clientCredential: new ClientCredential(
applicationId,
new SecureClientSecret(applicationSecret))).Result;
Console.WriteLine("End of run");
}
Here's the code snippet pulled from Microsoft Learn (https://learn.microsoft.com/en-us/mem/intune/developer/data-warehouse-app-only-auth-) It seems the line with AuthenticationContext, ClientCredential and SecureClientSecret are depreciated. For example: [b]ClientCredential' is obsolete: 'Use ConfidentialClientApplicationBuilder.WithCertificate or WithClientSecret instead.[/b] I cannot get this code snippet to work. [code]using System.Security; using System.Configuration; using Microsoft.Identity.Client;
class IntuneDataWarehouse { public static void Main() { Console.WriteLine("Intune Datawarehouse Start");
var applicationId = ConfigurationManager.AppSettings["appId"].ToString(); SecureString applicationSecret = ConvertToSecureStr(ConfigurationManager.AppSettings["appKey"].ToString()); // Load as SecureString from configuration file or secret store (i.e. Azure KeyVault) var tenantDomain = ConfigurationManager.AppSettings["tenantDomain"].ToString(); var msalContext = new AuthenticationContext($"https://login.windows.net/" + tenantDomain + "/oauth2/token");
AuthenticationResult authResult = msalContext.AcquireTokenAsync( resource: "https://api.manage.microsoft.com/", clientCredential: new ClientCredential( applicationId, new SecureClientSecret(applicationSecret))).Result;
Console.WriteLine("End of run"); } [/code] Has anyone worked on similar code?