Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Unanswered

Unable to connect using OAuth 2 from a console app with connection string and LoginPrompt=never using XRMTooling api when running from console app which is task scheduled.

(0) ShareShare
ReportReport
Posted on by 20

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.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 293,274 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,947 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans