Describe the bug
Unable to connect to D365 CE online using XRMCrmSvcClient with OAuth Authentication type where the loginPrompt= Never. The connection to dynamics 365 CE online is part of the console app which is task scheduled to run.
Expected behavior
The console app when task scheduled should automatically connect and the xrm tooling api CrmSvcClient.IsReady should return true, i get this when i normally debug within visual studio or unit test it.
**Actual behavior **
The xrmtooling api using within Console app should automatically connect to D365 CE online when the Console application is task scheduled to run. but this throws an ADAL error which states that it required user interaction.
ERROR REQUESTING Token FROM THE Authentication context - General ADAL Error
user_interaction_required: One of two conditions was encountered: 1. The PromptBehavior.Never flag was passed, but the constraint could not be honored, because user interaction was required. 2. An error occurred during a silent web authentication that prevented the http authentication flow from completing in a short enough time frameUnable to connect to CRM: user_interaction_required: One of two conditions was encountered: 1. The PromptBehavior.Never flag was passed, but the constraint could not be honored, because user interaction was required. 2. An error occurred during a silent web authentication that prevented the http authentication flow from completing in a short enough time frame
user_interaction_required: One of two conditions was encountered: 1. The PromptBehavior.Never flag was passed, but the constraint could not be honored, because user interaction was required. 2. An error occurred during a silent web authentication that prevented the http authentication flow from completing in a short enough time frameUnable to Login to Dynamics CRM
Unable to Login to Dynamics CRMOrganizationWebProxyClient is null
OrganizationWebProxyClient is null
To Reproduce
Code Snippent
string _connectionString = string.Format("AuthType=OAuth;Url={0};AppId={1};RedirectUri={2};TokenCacheStorePath={3};LoginPrompt=Never", _configuration.ServiceUrl, _configuration.ClientId, _configuration.RedirectUrl, _configuration.TokenPath);
switch (authenticationType)
{
case AuthenticationType.OAuth:
try
{
CrmServiceClient crmServiceClient = null;
//Hook Implementation as advised by microsoft for handling the persistance of token
//to the crmserviceclient object
#region OAuth Hook
_hook = new OAuthOverideHookImplements(_configuration);
// Call your existing authentication implementation
_accessToken = _hook.GetAccessTokenFromAzureADAsync(new Uri(_configuration.ServiceUrl));
_hook.AddAccessToken(new Uri(_configuration.ServiceUrl), _accessToken);
CrmServiceClient.AuthOverrideHook = _hook;
fileNamePath = CreateCacheToken(_path);
#endregion
await Task.Run(()
=> crmServiceClient = new CrmServiceClient(_connectionString)); // test token path
System.Diagnostics.Debug.WriteLine("CrmServiceClient" + ":" + crmServiceClient.IsReady);
if (File.Exists(fileNamePath))
{
File.Delete(fileNamePath);// delete the file once the object is returned
System.Diagnostics.Debug.WriteLine("File Deleted");
}
return crmServiceClient;
}
catch (Exception ex)
{
throw ex;
}
finally
{
// double check
if (File.Exists(fileNamePath))
{
File.Delete(fileNamePath);// delete the file once the object is returned
}
}
default:
return null;
}
}
Environment:
- Dynamics 365 CE Online.
- Microsoft.CrmSdk.CoreAssemblies v9.0.2.26
- Windows 7 Enterprise
- Visual Studio 2019
Application Details
Console application using ConfidentialClientApplicationBuilder as per AAD design guidelines for Native/Daemon/Service type application.