Add an "account name" (app name) field to make finding keys in keychain browser easier

codemagic-setup
Hank Grabowski 2023-03-06 21:39:21 -05:00
rodzic 9ac3ebc85c
commit fbc45b1acb
1 zmienionych plików z 17 dodań i 1 usunięć

Wyświetl plik

@ -10,6 +10,8 @@ import '../models/auth/oauth_credentials.dart';
import '../models/auth/profile.dart';
import '../models/exec_error.dart';
const _storageAccountName = 'social.myportal.relatica.secure_storage';
class SecretsService {
static const _basicProfilesKey = 'basic_profiles';
static const _oauthProfilesKey = 'oauth_profiles';
@ -21,8 +23,12 @@ class SecretsService {
final _secureStorage = const FlutterSecureStorage(
iOptions: IOSOptions(
accountName: _storageAccountName,
accessibility: KeychainAccessibility.first_unlock,
),
mOptions: MacOsOptions(
accountName: _storageAccountName,
),
);
FutureResult<List<Profile>, ExecError> initialize() async {
@ -108,7 +114,7 @@ class SecretsService {
_cachedProfiles.addAll(profiles);
}
Future<void> _saveJson<T>(
FutureResult<bool, ExecError> _saveJson<T>(
String key,
) async {
final json = _cachedProfiles
@ -117,5 +123,15 @@ class SecretsService {
.toList();
final jsonString = jsonEncode(json);
await _secureStorage.write(key: key, value: jsonString);
final pulledResult = await _secureStorage.read(key: key);
if (pulledResult == jsonString) {
return Result.ok(true);
}
return buildErrorResult(
type: ErrorType.localError,
message:
'For key $key value read from secure storage did not match value to secure storage',
);
}
}