[State Service] Getting authorization error without any change to bot code?
The bot was working unchanged for several months but now when it tries to get state data
activity.GetStateClient().BotState.GetUserData(activity.ChannelId, activity.From.Id);
it throws
Authorization for Microsoft App ID ... failed with status code Unauthorized.
I'm not sure why the code you've shared was working for several months, but now is not. What version of the BotBuilder sdk are you using? Have you tried calling MicrosoftAppCredentials.TrustServiceUrl(activity.ServiceUrl); before interacting with the state service?
Nonetheless, activity.GetStateClient() is being deprecated because it interacts with the default State Service (it is also being deprecated). Please refer to this blog post: https://blog.botframework.com/2017/12/19/bot-state-service-will-soon-retired-march-31st-2018/
Thank you Eric,
I tried it (MicrosoftAppCredentials.TrustServiceUrl(activity.ServiceUrl);) but it doesn't work either.
The exception is thrown by Microsoft.Bot.Connector.BotState (at line 125) and that class hasn't been changed more than a year.
I know that State Service is deprecated but it should work till the end of March, right?
Yes, the default state service should still work. However, the authentication scheme has changed since a year ago. What version of the SDK are you using? Have you tried upgrading to the latest? https://www.nuget.org/packages/Microsoft.Bot.Builder/
I upgraded the SDK to the latest version and tested with Bot Framework Emulator, but the error is the same and is raised by Microsoft.Bot.Connector.JwtTokenRefresher.SendAsync making request to http://localhost:1704/v3/botstate/emulator/conversations/.
I found the problem. It was the using of an older version of System.IdentityModel.Tokens.Jwt package.