Refresh-Token-Sample
Refresh-Token-Sample copied to clipboard
Android Refresh token with Retrofit, OkHttp, Kotlin Coroutines Mutex 🔂 When multiple requests hit 401 (HTTP_UNAUTHORIZED), only single Refresh token request will be executed. After successful refres...
Android Refresh Token Sample :repeat_one:
- Android Refresh token with Retrofit, OkHttp and Coroutines Mutex.
- When multiple requests hit 401 (HTTP_UNAUTHORIZED), only single
Refresh token request
will be executed. - After successful refresh, all pending requests will be executed concurrently.
- Store user and token using Proto DataStore from Jetpack.
- This example app shows how you can encrypt your data when using Proto DataStore from Jetpack.
Buy me a coffee
Liked some of my work? Buy me a coffee (or more likely a beer)
Features
- ✅ Refresh token only once for multiple requests
- ✅ Log out user if refreshToken failed
- ✅ Log out if user gets an error after first refreshing
- ✅ Queue all requests while token is being refreshed
Run local server
cd server
npm i
npm run start
- Change
baseUrl
(e.g.http://YOUR_ID_ADDRESS:3000/
) atapp/src/main/java/com/hoc081098/refreshtokensample/data/DataModule.kt
- Change
expiresIn
(default value is 1 minute) atserver/routes/index.js
.
Find this repository useful? ❤️
Star this repository and follow me for next creations! Thanks for your support 💗💗.