The Garage SDKs, in the open
garage_auth, garage_entitlements, garage_iap and garage_ui, moved out of Garage-Services and Metro-Map-Maker into one public repo. MIT, one readme, docs under docs/. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013F4NWNvYcdeSgqbWMT1VQ7
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
import "package:flutter_secure_storage/flutter_secure_storage.dart";
|
||||
|
||||
// small key/value seam so the token storage backend is swappable. the default
|
||||
// is flutter_secure_storage which covers mobile + desktop properly and falls
|
||||
// back to a best-effort impl on web. anyone embedding the SDK can hand us their
|
||||
// own (e.g. an in-memory one for tests, or shared_prefs if they dont care).
|
||||
abstract class TokenStore {
|
||||
Future<String?> read(String key);
|
||||
Future<void> write(String key, String value);
|
||||
Future<void> delete(String key);
|
||||
}
|
||||
|
||||
class SecureTokenStore implements TokenStore {
|
||||
SecureTokenStore({FlutterSecureStorage? storage})
|
||||
: _storage = storage ?? const FlutterSecureStorage();
|
||||
|
||||
final FlutterSecureStorage _storage;
|
||||
|
||||
@override
|
||||
Future<String?> read(String key) => _storage.read(key: key);
|
||||
|
||||
@override
|
||||
Future<void> write(String key, String value) =>
|
||||
_storage.write(key: key, value: value);
|
||||
|
||||
@override
|
||||
Future<void> delete(String key) => _storage.delete(key: key);
|
||||
}
|
||||
|
||||
// handy for tests, or platforms where you explicitly dont want persistence.
|
||||
class MemoryTokenStore implements TokenStore {
|
||||
final Map<String, String> _m = {};
|
||||
|
||||
@override
|
||||
Future<String?> read(String key) async => _m[key];
|
||||
|
||||
@override
|
||||
Future<void> write(String key, String value) async => _m[key] = value;
|
||||
|
||||
@override
|
||||
Future<void> delete(String key) async => _m.remove(key);
|
||||
}
|
||||
Reference in New Issue
Block a user