botframework-sdk icon indicating copy to clipboard operation
botframework-sdk copied to clipboard

[State Service] Getting authorization error without any change to bot code?

Open mitkodi opened this issue 8 years ago • 5 comments

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.

mitkodi avatar Jan 24 '18 16:01 mitkodi

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/

EricDahlvang avatar Jan 24 '18 23:01 EricDahlvang

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?

mitkodi avatar Jan 25 '18 19:01 mitkodi

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/

EricDahlvang avatar Jan 25 '18 22:01 EricDahlvang

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/.

mitkodi avatar Feb 01 '18 09:02 mitkodi

I found the problem. It was the using of an older version of System.IdentityModel.Tokens.Jwt package.

mitkodi avatar Feb 01 '18 11:02 mitkodi