android-templates
android-templates copied to clipboard
Add TokenAuthenticator setup
Why
Most of the apps use API requests and have a refresh token
mechanism to request new access tokens in case they expire. We don't have the setup for the initial TokenAuthenticator
yet, so we should add it to our templates.
The initial Authenticator needs to contain:
- max attempt/retry logic (normally set to 3).
- make use of
synchronized(this) {}
when executing the refresh token and rebuild the request to handle multiple authenticator calls at a time. - try/catch wrapping to catch errors during token refreshing. The default action in case an error has occurred.
Who Benefits?
Developers
who use this template to initialize their project with network requests.
I think this is essential because most of apps have API request and have refresh token mechanism. Having a standard setup would help us a lot in development and reduce mistakes.
Example of implementation: https://github.com/nimblehq/toyota-wallet-android/blob/main/data/src/main/java/co/omise/gcpf/service/authenticator/ApplicationRequestAuthenticator.kt
@hoangnguyen92dn @ryan-conway @nimblehq/chapter-android According to some edge cases we have faced and resolved in the recent projects regarding the refresh-token mechanism, this task should be in a higher priority to prepare the stable implementation for the following projects.