GetStream / stream-chat-swift

💬 iOS Chat SDK in Swift - Build your own app chat experience for iOS using the official Stream Chat API
https://getstream.io/chat/sdk/ios/
Other
859 stars 211 forks source link

`TokenProvider` is not invoked upon token expiration errors #2247

Closed bradleyrzeller closed 2 years ago

bradleyrzeller commented 2 years ago

What did you do?

Connected a ChatClient with a token set to expire shortly after.

What did you expect to happen?

I expected the TokenProvider to be invoked upon token expiration.

What happened instead?

The client disconnected without any attempt to refresh the token with the TokenProvider

GetStream Environment

GetStream Chat version: 4.20.0 GetStream Chat frameworks: StreamChat, StreamChatUI iOS version: 15.5 Swift version:: 5 Xcode version: 13.4.1 Device: iPhone 13 pro sim (iOS 15.5)

Additional context

It seems to be because the RequestDecoder is failing to decode an error payload into an ErrorPayload on this line. The actual payload I am seeing is

{
  "code" : 40,
  "message" : "SendEvent failed with error: \"JWTAuth error: token is expired (exp)\"",
  "more_info" : "https:\/\/getstream.io\/chat\/docs\/api_errors_response",
  "StatusCode" : 401,
  "duration" : ""
}

but the ErrorPayload expects a details key.

This throws off downstream logic that detects token expiration and triggers a refresh...

nuno-vieira commented 2 years ago

Hi @bradleyrzeller!

Thank you for the error report and your investigation. We are already looking into the issue 👍

Best, Nuno

polqf commented 2 years ago

Hi @bradleyrzeller

We've detected the issue and our backend team is deploying a hotfix for it. Thank you for the report, and sorry for the inconvenience!

polqf commented 2 years ago

@bradleyrzeller the issue should be fixed now. The fix is live, and we've verified it on our end as well. Please let us know if there's any other problem you are facing

bradleyrzeller commented 2 years ago

Hi @polqf and @nuno-vieira, I am still seeing the same broken behavior. The error payloads seem to still not include the expected key details:

2022-08-25 12:35:20.941 [ERROR] [com.apple.NSURLSession-delegate] [RequestDecoder.swift:51] [decodeRequestResponse(data:response:error:)] > API request failed with status code: 401, response:
{
  "code" : 40,
  "message" : "QueryChannels failed with error: \"JWTAuth error: token is expired (exp)\"",
  "more_info" : "https:\/\/getstream.io\/chat\/docs\/api_errors_response",
  "StatusCode" : 401,
  "duration" : ""
})

As such, the token provider is still not getting triggered upon token expiration.

polqf commented 2 years ago

Hi @bradleyrzeller ,

This is unfortunate! Maybe there is a location where we did not successfully deploy the fix 🙏 Sorry once again. We'll have a look first thing tomorrow. If you can, could you please share your app id with me at pol.quintana@getstream.io?

bradleyrzeller commented 2 years ago

Thanks Pol. I just emailed it to you.