1
1
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
// SPDX-License-Identifier: Apache-2.0
3
3
4
+ import 'package:amplify_auth_cognito_dart/amplify_auth_cognito_dart.dart' ;
4
5
import 'package:amplify_auth_cognito_dart/src/credentials/cognito_keys.dart' ;
5
6
import 'package:amplify_auth_cognito_dart/src/model/cognito_device_secrets.dart' ;
6
7
import 'package:amplify_auth_cognito_dart/src/sdk/cognito_identity_provider.dart' ;
7
8
import 'package:amplify_core/amplify_core.dart' ;
9
+ // ignore: implementation_imports
10
+ import 'package:amplify_core/src/config/amplify_outputs/auth/auth_outputs.dart' ;
8
11
import 'package:amplify_secure_storage_dart/amplify_secure_storage_dart.dart' ;
9
12
10
13
/// {@template amplify_auth_cognito_dart.credentials.device_metadata_repository}
@@ -13,26 +16,32 @@ import 'package:amplify_secure_storage_dart/amplify_secure_storage_dart.dart';
13
16
class DeviceMetadataRepository {
14
17
/// {@macro amplify_auth_cognito_dart.credentials.device_metadata_repository}
15
18
const DeviceMetadataRepository (
16
- this ._userPoolConfig ,
19
+ this ._authOutputs ,
17
20
this ._secureStorage,
18
21
);
19
22
20
23
/// {@macro amplify_auth_cognito_dart.credentials.device_metadata_repository}
21
24
factory DeviceMetadataRepository .fromDependencies (
22
25
DependencyManager dependencies,
23
- ) =>
24
- DeviceMetadataRepository (
25
- dependencies.expect (),
26
- dependencies.getOrCreate (),
27
- );
26
+ ) {
27
+ final authOutputs = dependencies.expect <AuthOutputs >();
28
+ if (authOutputs.userPoolClientId == null ) {
29
+ throw const InvalidAccountTypeException .noUserPool ();
30
+ }
31
+ return DeviceMetadataRepository (
32
+ authOutputs,
33
+ dependencies.getOrCreate (),
34
+ );
35
+ }
28
36
29
- final CognitoUserPoolConfig _userPoolConfig ;
37
+ final AuthOutputs _authOutputs ;
30
38
final SecureStorageInterface _secureStorage;
31
39
32
40
/// Retrieves the device secrets for [username] .
33
41
Future <CognitoDeviceSecrets ?> get (String username) async {
34
42
CognitoDeviceSecrets ? deviceSecrets;
35
- final deviceKeys = CognitoDeviceKeys (_userPoolConfig.appClientId, username);
43
+ final deviceKeys =
44
+ CognitoDeviceKeys (_authOutputs.userPoolClientId! , username);
36
45
final deviceKey = await _secureStorage.read (
37
46
key: deviceKeys[CognitoDeviceKey .deviceKey],
38
47
);
@@ -61,7 +70,8 @@ class DeviceMetadataRepository {
61
70
62
71
/// Save the [deviceSecrets] for [username] .
63
72
Future <void > put (String username, CognitoDeviceSecrets deviceSecrets) async {
64
- final deviceKeys = CognitoDeviceKeys (_userPoolConfig.appClientId, username);
73
+ final deviceKeys =
74
+ CognitoDeviceKeys (_authOutputs.userPoolClientId! , username);
65
75
await _secureStorage.write (
66
76
key: deviceKeys[CognitoDeviceKey .deviceKey],
67
77
value: deviceSecrets.deviceKey,
@@ -82,7 +92,8 @@ class DeviceMetadataRepository {
82
92
83
93
/// Clears the device secrets for [username] .
84
94
Future <void > remove (String username) async {
85
- final deviceKeys = CognitoDeviceKeys (_userPoolConfig.appClientId, username);
95
+ final deviceKeys =
96
+ CognitoDeviceKeys (_authOutputs.userPoolClientId! , username);
86
97
for (final key in deviceKeys) {
87
98
await _secureStorage.delete (key: key);
88
99
}
0 commit comments