web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Unanswered

The user authentication failed! Re-Authenticating due to expired token after 12 hours in Dynamics 365

(0) ShareShare
ReportReport
Posted on by 10

Hi,

we are using WCF service which connects to Microsoft dynamic 365 Version 1612(8.2.23.16). we are using simplified connection as below and we are using two cached connections as we are fetching data from two dynamic servers.

The .Net framework is 4.6.2

The references are below 

<package id="Microsoft.CrmSdk.CoreAssemblies" version="9.0.2.34" targetFramework="net462" />
<package id="Microsoft.CrmSdk.Deployment" version="9.0.2.34" targetFramework="net462" />
<package id="Microsoft.CrmSdk.Workflow" version="9.0.2.34" targetFramework="net462" />
<package id="Microsoft.CrmSdk.XrmTooling.CoreAssembly" version="9.1.0.79" targetFramework="net462" />
<package id="Microsoft.IdentityModel.Clients.ActiveDirectory" version="5.2.9" targetFramework="net462" />

The service works great for about 12 hours only, but after that we are getting an error as ' The user authentication failed! ' and we notice the below in the CRM logs, the security token expires. 

Microsoft.Xrm.Tooling.Connector.CrmServiceClient Information: 8 : Validation of CRM Connection Complete, total duration: 00:00:06.6172066
Microsoft.Xrm.Tooling.Connector.CrmServiceClient Verbose: 16 : New Batch Manager Created, Max #of Batches:50000, Max #of RequestsPerBatch:5000
Microsoft.Xrm.Tooling.Connector.CrmServiceClient Verbose: 16 : Claims Connection Token Debug:
SecurityToken is Not Null
Current Time is: 05/30/2021 23:09:47 + 2 Min for ValidFrom Check Only
Token ValidFrom is 05/30/2021 23:09:40, Is Valid = True
Token ValidTo is 05/31/2021 11:09:40, Is Valid = True
Microsoft.Xrm.Tooling.Connector.CrmServiceClient Warning: 4 : Claims Connection reset tripped
SecurityToken is Not Null
Start From is Valid True
End At is Valid False
Microsoft.Xrm.Tooling.Connector.CrmServiceClient Warning: 4 : Re-Authenticating due to expired token @ 05/31/2021 07:19:18

we have used the below coding

In the webconfig file

  <add name="con1" connectionString="Url=**url**/Orgname;  Domain=domainname;    Username=domainname\***username***; Password=****; AuthType=Office365; RequireNewInstance=True;" />

  <add name="con2" connectionString="Url=**url**/Orgname;  Domain=domainname;    Username=domainname\***username***; Password=****; AuthType=Office365; RequireNewInstance=True;" />

 public OrganizationServiceProxy service;

 var client = CrmServiceClientCache.GetConn(ConfigurationManager.ConnectionStrings["con1"].ConnectionString);
 service = EASclient.OrganizationServiceProxy;

public static CrmServiceClient Get(string connectionString)
{
if (_internalCache.ContainsKey(connectionString)
&& _internalCache[connectionString] != null
&& _internalCache[connectionString].IsReady)
{
return _internalCache[connectionString];
}
else
{
lock (_objLock)
{
if (!_internalCache.ContainsKey(connectionString)
|| _internalCache[connectionString] == null
|| !_internalCache[connectionString].IsReady)
{
ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls12;

CrmServiceClient.MaxConnectionTimeout = new TimeSpan(0, 0, Convert.ToInt32(ConfigurationManager.AppSettings["CrmServiceClientTimeout"]));
CrmServiceClient crmClient = new CrmServiceClient(connectionString);
if (crmClient.IsReady)
{
_internalCache[connectionString] = crmClient ;
}
else
{
if (crmClient.LastCrmException != null)
throw crmClient.LastCrmException;

throw new InvalidOperationException(crmClient.LastCrmError);
}
}
return _internalCache[connectionString];
}
}
}

Why would the security token not renewed automatically. We are looking of the support to get this problem resolved.

I have the same question (0)
  • a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Hello,

    What CrmServiceClientCache is and what does GetConn method do?

  • DynaCRM Profile Picture
    10 on at

    CrmServiceClient Get(string connectionString) returns the cache connectionstring

    This function creates the CRMServiceClient and stores in the internalcache to reuse the connection.

    CrmServiceClient crmClient = new CrmServiceClient(connectionString);
    if (crmClient.IsReady)
    {
    _internalCache[connectionString] = crmClient ;
    }

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Microsoft Dynamics 365 | Integration, Dataverse, and general topics

#1
11manish Profile Picture

11manish 172

#2
ManoVerse Profile Picture

ManoVerse 58 Super User 2026 Season 1

#3
Niki Patel Profile Picture

Niki Patel 42

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans