Hi,
I'm trying to convert the ADAL use case into MSAL use case for one of our external applications.
It is accessing a custom web service using a clientid & clientsecret.
My previous code was like this
authenticationContext = new AuthenticationContext("">login.windows.net/tenantid");
credential = new ClientCredential("clientid", "clientsecret");
authenticationResult = authenticationContext.AcquireTokenAsync("baseurl of the server", credential).Result;
oAuthHeader = authenticationResult.CreateAuthorizationHeader();
var contract = new { _request = requestObjectForTheMethod }; // Anonymous object
HttpClient client = new HttpClient();
client.BaseAddress = new Uri("full url of the service");
client.DefaultRequestHeaders.Add("Authorization", oAuthHeader);
client.Timeout = TimeSpan.FromSeconds(1000);
HttpRequestMessage httpRequest = new HttpRequestMessage(HttpMethod.Post,
"full url of the service including the method name");
httpRequest.Content = new StringContent(JsonConvert.SerializeObject(contract),
Encoding.UTF8,
"application/json");
I tried to convert it but already got stuck on the fact it is not returning any accounts via GetAccountsAsync()
ConfidentialClientApplicationOptions options = new ConfidentialClientApplicationOptions()
{
ClientId = "clientid",
ClientSecret = "clientsecret",
TenantId = "tenantid"
};
var _clientApp = ConfidentialClientApplicationBuilder.CreateWithApplicationOptions(options)
.WithLogging(MyLoggingMethod, LogLevel.Info,
enablePiiLogging: true,
enableDefaultPlatformLogging: true)
.Build();
var accounts = _clientApp.GetAccountsAsync().Result;
var result = _clientApp.AcquireTokenSilent(scopes, accounts.FirstOrDefault()).ExecuteAsync();
Not sure what I need to do to get this working again ...
Any idea's ?
Regards,
Sven Peeters