microsoft / microsoft/Dynamics365-Apps-Samples
DynamicsDataAccessLayer unauthorized due to token expiration
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 184
- Forks
- 240
- PR merge metrics
- No merged PRs in 30d
Description
I have been using the Smart Assist Bot since it has come out. We have had no issues with the Bot using the API calls to D365 CE. However, in the last few months, the API calls stopped working due to an "unauthorized" error. It appears that the Access Token expires and a new one is not acquired until we restart the Bots App Services. The App Registration Secret is not expired. CORS is set correctly.
The API calls work for about 3 hours and then they stop due to unauthorized access. Again, this has been working for months and then this started a couple months ago.
Do I need to add code to Acquire a new Access Token each time? And, if so, how would I do this.
MS Ticket Logs:
traceName: LogAccessDenied ; area: Owin.AuthN ; layer: S2SSecurityTokenHandler ; message: empty ; exception: System.IdentityModel.Tokens.SecurityTokenExpiredException: IDX10223: Lifetime validation failed. The token is expired.
ValidTo: '07/28/2021 14:57:27'
Current time: '07/28/2021 15:22:00'.
at System.IdentityModel.Tokens.Validators.ValidateLifetime(Nullable1 notBefore, Nullable1 expires, SecurityToken securityToken, TokenValidationParameters validationParameters)
at System.IdentityModel.Tokens.JwtSecurityTokenHandler.ValidateLifetime(Nullable1 notBefore, Nullable1 expires, SecurityToken securityToken, TokenValidationParameters validationParameters)
at System.IdentityModel.Tokens.JwtSecurityTokenHandler.ValidateToken(String securityToken, TokenValidationParameters validationParameters, SecurityToken& validatedToken)
at Microsoft.Crm.Authentication.Owin.TokenHandlers.BaseSecurityTokenHandler.ValidateToken(String securityToken, TokenValidationParameters validationParameters, SecurityToken& validatedToken)
System.IdentityModel.Tokens.SecurityTokenExpiredException: IDX10223: Lifetime validation failed. The token is expired.
ValidTo: '07/28/2021 14:57:27'
Current time: '07/28/2021 15:22:00'.
at System.IdentityModel.Tokens.Validators.ValidateLifetime(Nullable1 notBefore, Nullable1 expires, SecurityToken securityToken, TokenValidationParameters validationParameters)
at System.IdentityModel.Tokens.JwtSecurityTokenHandler.ValidateLifetime(Nullable1 notBefore, Nullable1 expires, SecurityToken securityToken, TokenValidationParameters validationParameters)
at System.IdentityModel.Tokens.JwtSecurityTokenHandler.ValidateToken(String securityToken, TokenValidationParameters validationParameters, SecurityToken& validatedToken)
at Microsoft.Crm.Authentication.Owin.TokenHandlers.BaseSecurityTokenHandler.ValidateToken(String securityToken, TokenValidationParameters validationParameters, SecurityToken& validatedToken)
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the DynamicsDataAccessLayer and the entry point that acquires or reuses the access token for D365 CE API calls. Reproduce the unauthorized response after the approximately three-hour token lifetime and trace the existing token path. Done means API calls continue without restarting the Bot App Services after the token expires.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- api, authentication
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100