mirror of
https://gitlab.com/mysocialportal/relatica
synced 2024-10-18 15:53:32 +00:00
Add an "account name" (app name) field to make finding keys in keychain browser easier
This commit is contained in:
parent
9ac3ebc85c
commit
fbc45b1acb
1 changed files with 17 additions and 1 deletions
|
@ -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',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue