@@ -14,6 +14,8 @@ import 'package:amplify_auth_cognito_dart/src/credentials/legacy_credential_prov
14
14
import 'package:amplify_auth_cognito_dart/src/state/cognito_state_machine.dart' ;
15
15
// ignore: implementation_imports, invalid_use_of_internal_member
16
16
import 'package:amplify_auth_cognito_dart/src/state/state.dart' ;
17
+ // ignore: implementation_imports
18
+ import 'package:amplify_core/src/config/amplify_outputs/auth/auth_outputs.dart' ;
17
19
import 'package:amplify_flutter/amplify_flutter.dart' ;
18
20
import 'package:async/async.dart' ;
19
21
@@ -28,22 +30,21 @@ class LegacyCredentialProviderIOS implements LegacyCredentialProvider {
28
30
final CognitoAuthStateMachine _stateMachine;
29
31
30
32
@override
31
- Future <CredentialStoreData ?> fetchLegacyCredentials ({
32
- CognitoUserPoolConfig ? userPoolConfig,
33
- CognitoIdentityCredentialsProvider ? identityPoolConfig,
34
- CognitoOAuthConfig ? hostedUiConfig,
35
- }) async {
33
+ Future <CredentialStoreData ?> fetchLegacyCredentials (
34
+ AuthOutputs authOutputs,
35
+ ) async {
36
36
CognitoUserPoolTokens ? userPoolTokens;
37
- if (userPoolConfig != null ) {
37
+ final userPoolClientId = authOutputs.userPoolClientId;
38
+ if (userPoolClientId != null ) {
38
39
final userPoolStorage = await _getUserPoolStorage ();
39
- final cognitoUserKeys = LegacyCognitoUserKeys (userPoolConfig );
40
+ final cognitoUserKeys = LegacyCognitoUserKeys (userPoolClientId );
40
41
final currentUserId = await userPoolStorage.read (
41
42
key: cognitoUserKeys[LegacyCognitoKey .currentUser],
42
43
);
43
44
if (currentUserId != null ) {
44
45
final userPoolKeys = LegacyCognitoUserPoolKeys (
45
46
currentUserId,
46
- userPoolConfig ,
47
+ userPoolClientId ,
47
48
);
48
49
final accessToken = await userPoolStorage.read (
49
50
key: userPoolKeys[LegacyCognitoUserPoolKey .accessToken],
@@ -56,7 +57,7 @@ class LegacyCredentialProviderIOS implements LegacyCredentialProvider {
56
57
);
57
58
if (accessToken != null && refreshToken != null && idToken != null ) {
58
59
// TODO(Jordan-Nelson): fetch sign in method from keychain on iOS
59
- final signInMethod = hostedUiConfig != null
60
+ final signInMethod = authOutputs.oauth != null
60
61
? CognitoSignInMethod .hostedUi
61
62
: CognitoSignInMethod .default$;
62
63
userPoolTokens = CognitoUserPoolTokens (
@@ -71,7 +72,7 @@ class LegacyCredentialProviderIOS implements LegacyCredentialProvider {
71
72
72
73
String ? identityId;
73
74
AWSCredentials ? awsCredentials;
74
- final identityPoolId = identityPoolConfig ? .poolId ;
75
+ final identityPoolId = authOutputs.identityPoolId ;
75
76
if (identityPoolId != null ) {
76
77
final identityPoolStorage = await _getIdentityPoolStorage (
77
78
identityPoolId,
@@ -122,21 +123,20 @@ class LegacyCredentialProviderIOS implements LegacyCredentialProvider {
122
123
}
123
124
124
125
@override
125
- Future <void > deleteLegacyCredentials ({
126
- CognitoUserPoolConfig ? userPoolConfig,
127
- CognitoIdentityCredentialsProvider ? identityPoolConfig,
128
- CognitoOAuthConfig ? hostedUiConfig,
129
- }) async {
130
- if (userPoolConfig != null ) {
126
+ Future <void > deleteLegacyCredentials (
127
+ AuthOutputs authOutputs,
128
+ ) async {
129
+ final userPoolClientId = authOutputs.userPoolClientId;
130
+ if (userPoolClientId != null ) {
131
131
final userPoolStorage = await _getUserPoolStorage ();
132
- final cognitoUserKeys = LegacyCognitoUserKeys (userPoolConfig );
132
+ final cognitoUserKeys = LegacyCognitoUserKeys (userPoolClientId );
133
133
final currentUser = await userPoolStorage.read (
134
134
key: cognitoUserKeys[LegacyCognitoKey .currentUser],
135
135
);
136
136
if (currentUser != null ) {
137
137
final userPoolKeys = LegacyCognitoUserPoolKeys (
138
138
currentUser,
139
- userPoolConfig ,
139
+ userPoolClientId ,
140
140
);
141
141
await userPoolStorage.deleteMany ([
142
142
userPoolKeys[LegacyCognitoUserPoolKey .accessToken],
@@ -147,9 +147,9 @@ class LegacyCredentialProviderIOS implements LegacyCredentialProvider {
147
147
}
148
148
}
149
149
150
- final identityPoolId = identityPoolConfig ? .poolId;
151
- if (identityPoolId != null ) {
152
- final identityPoolStorage = await _getIdentityPoolStorage (identityPoolId);
150
+ if (authOutputs. identityPoolId != null ) {
151
+ final identityPoolStorage =
152
+ await _getIdentityPoolStorage (authOutputs. identityPoolId! );
153
153
const identityPoolKeys = LegacyCognitoIdentityPoolKeys ();
154
154
await identityPoolStorage.deleteMany ([
155
155
identityPoolKeys[LegacyCognitoIdentityPoolKey .identityId],
@@ -162,20 +162,22 @@ class LegacyCredentialProviderIOS implements LegacyCredentialProvider {
162
162
}
163
163
164
164
@override
165
- Future <LegacyDeviceDetails ?> fetchLegacyDeviceSecrets ({
166
- required String username,
167
- CognitoUserPoolConfig ? userPoolConfig,
168
- }) async {
169
- if (userPoolConfig == null ) return null ;
165
+ Future <LegacyDeviceDetails ?> fetchLegacyDeviceSecrets (
166
+ String username,
167
+ AuthOutputs authOutputs,
168
+ ) async {
169
+ final userPoolClientId = authOutputs.userPoolClientId;
170
+ if (userPoolClientId == null ) return null ;
170
171
final userPoolStorage = await _getUserPoolStorage ();
171
- final cognitoUserKeys = LegacyCognitoUserKeys (userPoolConfig );
172
+ final cognitoUserKeys = LegacyCognitoUserKeys (userPoolClientId );
172
173
final currentUserId = await userPoolStorage.read (
173
174
key: cognitoUserKeys[LegacyCognitoKey .currentUser],
174
175
);
175
- if (currentUserId == null ) return null ;
176
+ final userPoolId = authOutputs.userPoolId;
177
+ if (currentUserId == null || userPoolId == null ) return null ;
176
178
final keys = LegacyDeviceSecretKeys (
177
179
currentUserId,
178
- userPoolConfig ,
180
+ userPoolId ,
179
181
);
180
182
final deviceKey = await userPoolStorage.read (
181
183
key: keys[LegacyDeviceSecretKey .id],
@@ -187,7 +189,7 @@ class LegacyCredentialProviderIOS implements LegacyCredentialProvider {
187
189
key: keys[LegacyDeviceSecretKey .group],
188
190
);
189
191
190
- final asfKeys = LegacyAsfDeviceKeys (currentUserId, userPoolConfig );
192
+ final asfKeys = LegacyAsfDeviceKeys (currentUserId, userPoolId );
191
193
final asfDeviceId = await userPoolStorage.read (
192
194
key: asfKeys[LegacyAsfDeviceKey .id],
193
195
);
@@ -201,19 +203,21 @@ class LegacyCredentialProviderIOS implements LegacyCredentialProvider {
201
203
}
202
204
203
205
@override
204
- Future <void > deleteLegacyDeviceSecrets ({
205
- required String username,
206
- CognitoUserPoolConfig ? userPoolConfig,
207
- }) async {
208
- if (userPoolConfig == null ) return ;
206
+ Future <void > deleteLegacyDeviceSecrets (
207
+ String username,
208
+ AuthOutputs authOutputs,
209
+ ) async {
210
+ final userPoolClientId = authOutputs.userPoolClientId;
211
+ if (userPoolClientId == null ) return ;
209
212
final userPoolStorage = await _getUserPoolStorage ();
210
- final cognitoUserKeys = LegacyCognitoUserKeys (userPoolConfig );
213
+ final cognitoUserKeys = LegacyCognitoUserKeys (userPoolClientId );
211
214
final currentUserId = await userPoolStorage.read (
212
215
key: cognitoUserKeys[LegacyCognitoKey .currentUser],
213
216
);
214
- if (currentUserId == null ) return ;
215
- final keys = LegacyDeviceSecretKeys (currentUserId, userPoolConfig);
216
- final asfKeys = LegacyAsfDeviceKeys (currentUserId, userPoolConfig);
217
+ final userPoolId = authOutputs.userPoolId;
218
+ if (currentUserId == null || userPoolId == null ) return ;
219
+ final keys = LegacyDeviceSecretKeys (currentUserId, userPoolId);
220
+ final asfKeys = LegacyAsfDeviceKeys (currentUserId, userPoolId);
217
221
await userPoolStorage.deleteMany ([
218
222
keys[LegacyDeviceSecretKey .id],
219
223
keys[LegacyDeviceSecretKey .secret],
0 commit comments