QueuedInterceptor token updating problem #2302
Unanswered
I-m-good-man
asked this question in
Q&A
Replies: 1 comment
-
https://github.com/cfug/dio/blob/main/example_dart/lib/queued_interceptor_crsftoken.dart |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I understand correctly that the QueuedInterceptor works as follows?:
The interceptor in the queue sends a request and blocks the processing of further requests until it receives a response to the sent request and processes it in the response/error processing method.
If it doesn't work that way, then there is the following problem with updating tokens in the interseptor's response processing method:
If the client sends 2 requests to the server with an invalid bearer token, it receives 2 responses with the error 401 Unauthorized (the token is not valid). The QueuedInterceptor must process these 2 erroneous responses in turn - in each call to the processing method, the interсeptor updates a pair of tokens through a refresh token.
After processing the first response, a pair of tokens was updated and now the bearer token on the client side is valid. But, the interceptor must also process the second 401 response. The interceptor does not know that a pair of tokens has already been updated, so it initiates a re-update of an already fresh pair of tokens.
And there can be more than two requests with an invalid token, so the QueuedInterceptor can initiate many updates of a pair of tokens.
Beta Was this translation helpful? Give feedback.
All reactions