Skip to content

codebythura/Refresh_Access_Token_Flow

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

24 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ” Refresh Token Flow Example (Ktor Server + Flutter Client)

This repository demonstrates a complete working example of handling access token refreshing in a client-server architecture using:

  • Ktor as the backend server
  • Flutter as the mobile client app

πŸ“Œ Features

  • 🧾 JWT-based authentication with access and refresh tokens
  • ⏱ Access token expires in 1 minute (for testing)
  • ♻️ Refresh token expires in 2 minutes
  • πŸ”„ Automatic access token refresh when expired
  • πŸšͺ Forced logout when refresh token is also expired

πŸ› οΈ Components

βœ… Server (Ktor)

  • Exposes endpoints for:

    • /auth/signup
    • /auth/login
    • /auth/refresh
    • /get_data?userId
  • Generates JWTs using HMAC

  • Stores refresh tokens and validates them during token refresh

πŸ“± Client (Flutter)

  • Stores tokens securely using flutter_secure_storage

  • Intercepts HTTP 401 errors

    • Automatically retries the original request after refreshing the token
    • If refresh token is also expired, logs the user out
  • Uses state management BLoC to manage state

πŸš€ How to Run

  1. Start the Ktor Server
cd ktor-server
./gradlew run
  1. Run the Flutter App
cd flutter-client
flutter run

About

πŸ” Access Token Refresh Example with Ktor Server and Flutter Client

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published