localize_token_manager 1.0.0
localize_token_manager: ^1.0.0 copied to clipboard
A clean, customizable API service package with Dio and refresh token handling
A powerful set of tools for managing authentication tokens in Dart and Flutter applications.
A Dart package for seamless, secure, and automatic management of authentication tokens in your applications. localize_token_manager simplifies token injection, refresh, and multi-tenant support, making it easy to integrate robust authentication flows with minimal setup.
🚀 Features #
🔐 Automatic Token Management - Seamless token injection and refresh 🔄 Token Refresh - Automatic handling of expired tokens 🛡️ Security - Built with security best practices 📊 Logging - Optional request/response logging 🚀 Type-Safe - Generic response types with JSON parsing ⚡ Easy to Use - Simple, intuitive API 🔧 Customizable - Flexible configuration options 🌐 Multi-Tenant - Support for different tenants/domains
➡️ Getting Started #
1. Install the package #
For Dart:
dart pub add localize_token_manager
For Flutter:
flutter pub add localize_token_manager
2. Import the package #
Add this import to your Dart code:
import 'package:localize_token_manager/localize_token_manager.dart';
3. Initialize and use #
See the Usage section below for a complete example of initialization and making requests.
✅ Usage #
import 'package:localize_token_manager/localize_token_manager.dart';
void main() {
// Initialize the token manager
final tokenManager = LocalizeTokenManager(
baseUrl: 'https://api.example.com',
enabledLogging: true, // Enable request/response logging
);
Future<dynamic> request({
required String endpoint,
required HttpMethod method,
Map<String, dynamic>? body,
Map<String, String>? headers,
}) async {
final LocalizeTokenManager api = LocalizeTokenManager(
baseUrl: Environment.baseUrl,
enabledLogging: true,
);
api.initialize(
tokenProvider: () async => await SecureStorageHelper.getAccessToken(),
refreshToken: () {
final obj = {
"name": "refresh_token",
"requestUrl": 'request_url',
};
return obj;
},
tenantKey: () async => await SecureStorageHelper.getTenantKey(),
onUnauthorized: () async {
// Handle logout / redirect to login
// await LocalizeTokenManager.logOut();
// Use Navigator or your auth state management to go to login screen
print('➡️ Unauthorized - Logging out');
},
);
final response = await api.request(
endpoint: endpoint,
method: method,
body: body,
headers: headers,
);
return response;
}
}