From f24cb2cfdb11da68beee4520456daec598cc0ee2 Mon Sep 17 00:00:00 2001 From: dab246 Date: Mon, 11 Sep 2023 10:23:08 +0700 Subject: [PATCH] Add `adr` to fix oidc refresh token using `QueuedInterceptor` (cherry picked from commit f50bc503619fa6018cef87c29a3e2c7227e6ee6d) --- docs/adr/0031-fix-refresh-token-with-oidc.md | 29 ++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 docs/adr/0031-fix-refresh-token-with-oidc.md diff --git a/docs/adr/0031-fix-refresh-token-with-oidc.md b/docs/adr/0031-fix-refresh-token-with-oidc.md new file mode 100644 index 000000000..3e28cf293 --- /dev/null +++ b/docs/adr/0031-fix-refresh-token-with-oidc.md @@ -0,0 +1,29 @@ +# 30. Fix refresh token with OIDC using `QueuedInterceptor` + +Date: 2023-09-11 + +## Status + +- Issue: + +[1974](https://github.com/linagora/tmail-flutter/issues/1974) + +## Context + +- Requests still return `401` after retrieving a new token. The application automatically logs out + +## Root cause + +- When executing tasks concurrently, they are pushed into the `Queue` along with the old `header` values (the old authentication is retained). +So when the first request receives a `401` error and tries to get a new token, it will be updated with the new authentication header value. + +## Decision + +- Use `QueuedInterceptor` to serialize `requests/responses/errors` before they enter the interceptor. +If there are multiple concurrent requests, the request is added to a queue before entering the interceptor. +Only one request at a time enters the interceptor, and after that request is processed by the interceptor, the next request will enter the interceptor. +- Try to make a `retry` request up to 3 times when receiving a `401` error. Aims to update the new token value on `memmory` to requests in the `queue`. + +## Consequences + +- The following `requests` were completed successfully. The application is not automatically logged out