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, Nullable
1 expires, SecurityToken securityToken, TokenValidationParameters validationParameters)
at System.IdentityModel.Tokens.JwtSecurityTokenHandler.ValidateLifetime(Nullable1 notBefore, Nullable
1 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, Nullable
1 expires, SecurityToken securityToken, TokenValidationParameters validationParameters)
at System.IdentityModel.Tokens.JwtSecurityTokenHandler.ValidateLifetime(Nullable1 notBefore, Nullable
1 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)