@@ -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
+ if (authOutputs.userPoolClientId != null ) {
38
38
final userPoolStorage = await _getUserPoolStorage ();
39
- final cognitoUserKeys = LegacyCognitoUserKeys (userPoolConfig);
39
+ final cognitoUserKeys =
40
+ LegacyCognitoUserKeys (authOutputs.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
+ authOutputs.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,10 +72,9 @@ class LegacyCredentialProviderIOS implements LegacyCredentialProvider {
71
72
72
73
String ? identityId;
73
74
AWSCredentials ? awsCredentials;
74
- final identityPoolId = identityPoolConfig? .poolId;
75
- if (identityPoolId != null ) {
75
+ if (authOutputs.identityPoolId != null ) {
76
76
final identityPoolStorage = await _getIdentityPoolStorage (
77
- identityPoolId,
77
+ authOutputs. identityPoolId! ,
78
78
);
79
79
const identityPoolKeys = LegacyCognitoIdentityPoolKeys ();
80
80
identityId = await identityPoolStorage.read (
@@ -122,21 +122,20 @@ class LegacyCredentialProviderIOS implements LegacyCredentialProvider {
122
122
}
123
123
124
124
@override
125
- Future <void > deleteLegacyCredentials ({
126
- CognitoUserPoolConfig ? userPoolConfig,
127
- CognitoIdentityCredentialsProvider ? identityPoolConfig,
128
- CognitoOAuthConfig ? hostedUiConfig,
129
- }) async {
130
- if (userPoolConfig != null ) {
125
+ Future <void > deleteLegacyCredentials (
126
+ AuthOutputs authOutputs,
127
+ ) async {
128
+ if (authOutputs.userPoolClientId != null ) {
131
129
final userPoolStorage = await _getUserPoolStorage ();
132
- final cognitoUserKeys = LegacyCognitoUserKeys (userPoolConfig);
130
+ final cognitoUserKeys =
131
+ LegacyCognitoUserKeys (authOutputs.userPoolClientId! );
133
132
final currentUser = await userPoolStorage.read (
134
133
key: cognitoUserKeys[LegacyCognitoKey .currentUser],
135
134
);
136
135
if (currentUser != null ) {
137
136
final userPoolKeys = LegacyCognitoUserPoolKeys (
138
137
currentUser,
139
- userPoolConfig ,
138
+ authOutputs.userPoolClientId ! ,
140
139
);
141
140
await userPoolStorage.deleteMany ([
142
141
userPoolKeys[LegacyCognitoUserPoolKey .accessToken],
@@ -147,9 +146,9 @@ class LegacyCredentialProviderIOS implements LegacyCredentialProvider {
147
146
}
148
147
}
149
148
150
- final identityPoolId = identityPoolConfig ? .poolId;
151
- if (identityPoolId != null ) {
152
- final identityPoolStorage = await _getIdentityPoolStorage (identityPoolId);
149
+ if (authOutputs. identityPoolId != null ) {
150
+ final identityPoolStorage =
151
+ await _getIdentityPoolStorage (authOutputs. identityPoolId! );
153
152
const identityPoolKeys = LegacyCognitoIdentityPoolKeys ();
154
153
await identityPoolStorage.deleteMany ([
155
154
identityPoolKeys[LegacyCognitoIdentityPoolKey .identityId],
@@ -162,20 +161,21 @@ class LegacyCredentialProviderIOS implements LegacyCredentialProvider {
162
161
}
163
162
164
163
@override
165
- Future <LegacyDeviceDetails ?> fetchLegacyDeviceSecrets ({
166
- required String username,
167
- CognitoUserPoolConfig ? userPoolConfig ,
168
- } ) async {
169
- if (userPoolConfig == null ) return null ;
164
+ Future <LegacyDeviceDetails ?> fetchLegacyDeviceSecrets (
165
+ String username,
166
+ AuthOutputs authOutputs ,
167
+ ) async {
168
+ if (authOutputs.userPoolClientId == null ) return null ;
170
169
final userPoolStorage = await _getUserPoolStorage ();
171
- final cognitoUserKeys = LegacyCognitoUserKeys (userPoolConfig);
170
+ final cognitoUserKeys =
171
+ LegacyCognitoUserKeys (authOutputs.userPoolClientId! );
172
172
final currentUserId = await userPoolStorage.read (
173
173
key: cognitoUserKeys[LegacyCognitoKey .currentUser],
174
174
);
175
- if (currentUserId == null ) return null ;
175
+ if (currentUserId == null || authOutputs.userPoolId == null ) return null ;
176
176
final keys = LegacyDeviceSecretKeys (
177
177
currentUserId,
178
- userPoolConfig ,
178
+ authOutputs.userPoolId ! ,
179
179
);
180
180
final deviceKey = await userPoolStorage.read (
181
181
key: keys[LegacyDeviceSecretKey .id],
@@ -187,7 +187,7 @@ class LegacyCredentialProviderIOS implements LegacyCredentialProvider {
187
187
key: keys[LegacyDeviceSecretKey .group],
188
188
);
189
189
190
- final asfKeys = LegacyAsfDeviceKeys (currentUserId, userPoolConfig );
190
+ final asfKeys = LegacyAsfDeviceKeys (currentUserId, authOutputs.userPoolId ! );
191
191
final asfDeviceId = await userPoolStorage.read (
192
192
key: asfKeys[LegacyAsfDeviceKey .id],
193
193
);
@@ -201,19 +201,20 @@ class LegacyCredentialProviderIOS implements LegacyCredentialProvider {
201
201
}
202
202
203
203
@override
204
- Future <void > deleteLegacyDeviceSecrets ({
205
- required String username,
206
- CognitoUserPoolConfig ? userPoolConfig ,
207
- } ) async {
208
- if (userPoolConfig == null ) return ;
204
+ Future <void > deleteLegacyDeviceSecrets (
205
+ String username,
206
+ AuthOutputs authOutputs ,
207
+ ) async {
208
+ if (authOutputs.userPoolClientId == null ) return ;
209
209
final userPoolStorage = await _getUserPoolStorage ();
210
- final cognitoUserKeys = LegacyCognitoUserKeys (userPoolConfig);
210
+ final cognitoUserKeys =
211
+ LegacyCognitoUserKeys (authOutputs.userPoolClientId! );
211
212
final currentUserId = await userPoolStorage.read (
212
213
key: cognitoUserKeys[LegacyCognitoKey .currentUser],
213
214
);
214
- if (currentUserId == null ) return ;
215
- final keys = LegacyDeviceSecretKeys (currentUserId, userPoolConfig );
216
- final asfKeys = LegacyAsfDeviceKeys (currentUserId, userPoolConfig );
215
+ if (currentUserId == null || authOutputs.userPoolId == null ) return ;
216
+ final keys = LegacyDeviceSecretKeys (currentUserId, authOutputs.userPoolId ! );
217
+ final asfKeys = LegacyAsfDeviceKeys (currentUserId, authOutputs.userPoolId ! );
217
218
await userPoolStorage.deleteMany ([
218
219
keys[LegacyDeviceSecretKey .id],
219
220
keys[LegacyDeviceSecretKey .secret],
0 commit comments