web
You’re offline. This is a read only version of the page.
close
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.

I have the same question (0)

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 70 Super User 2025 Season 2

#2
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 33 Most Valuable Professional

#3
Daniyal Khaleel Profile Picture

Daniyal Khaleel 32 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans