@@ -29,6 +29,8 @@ import 'package:amplify_auth_cognito_dart/src/sdk/sdk_bridge.dart';
29
29
import 'package:amplify_auth_cognito_dart/src/state/cognito_state_machine.dart' ;
30
30
import 'package:amplify_auth_cognito_dart/src/state/state.dart' ;
31
31
import 'package:amplify_core/amplify_core.dart' ;
32
+ // ignore: implementation_imports
33
+ import 'package:amplify_core/src/config/amplify_outputs/auth/auth_outputs.dart' ;
32
34
import 'package:async/async.dart' ;
33
35
import 'package:built_collection/built_collection.dart' ;
34
36
import 'package:meta/meta.dart' ;
@@ -60,11 +62,22 @@ final class SignInStateMachine
60
62
late SignInParameters parameters;
61
63
62
64
/// The configured user pool.
63
- late final CognitoUserPoolConfig config = expect ();
65
+ // late final CognitoUserPoolConfig config = expect();
64
66
65
67
/// The configured identity pool.
68
+ // TODO(nikahsn): remove after refactoring CognitoIdentityPoolKeys to use
69
+ // AmplifyOutputs type
66
70
CognitoIdentityCredentialsProvider ? get identityPoolConfig => get ();
67
71
72
+ AuthOutputs get _authOutputs {
73
+ final authOutputs = get <AuthOutputs >();
74
+ if (authOutputs? .userPoolId == null ||
75
+ authOutputs? .userPoolClientId == null ) {
76
+ throw const InvalidAccountTypeException .noUserPool ();
77
+ }
78
+ return authOutputs! ;
79
+ }
80
+
68
81
/// The Cognito Identity Provider service client.
69
82
late final CognitoIdentityProviderClient cognitoIdentityProvider = expect ();
70
83
@@ -344,7 +357,7 @@ final class SignInStateMachine
344
357
if (_user.deviceSecrets? .deviceKey case final deviceKey? )
345
358
CognitoConstants .challengeParamDeviceKey: deviceKey,
346
359
})
347
- ..clientId = config.appClientId
360
+ ..clientId = _authOutputs.userPoolClientId
348
361
..clientMetadata.addAll (event.clientMetadata)
349
362
..analyticsMetadata = get <AnalyticsMetadataType >()? .toBuilder (),
350
363
);
@@ -370,9 +383,10 @@ final class SignInStateMachine
370
383
final workerMessage = SrpPasswordVerifierMessage ((b) {
371
384
b
372
385
..initResult = initResult
373
- ..clientId = config.appClientId
374
- ..clientSecret = config.appClientSecret
375
- ..poolId = config.poolId
386
+ ..clientId = _authOutputs.userPoolClientId
387
+ // ignore: invalid_use_of_internal_member
388
+ ..clientSecret = _authOutputs.appClientSecret
389
+ ..poolId = _authOutputs.userPoolId
376
390
..deviceKey = _user.deviceSecrets? .deviceKey
377
391
..challengeParameters = BuiltMap (_publicChallengeParameters)
378
392
..parameters = SignInParameters (
@@ -394,7 +408,7 @@ final class SignInStateMachine
394
408
_initResult ?? = await _initSrp ();
395
409
return RespondToAuthChallengeRequest .build ((b) {
396
410
b
397
- ..clientId = config.appClientId
411
+ ..clientId = _authOutputs.userPoolClientId
398
412
..challengeName = ChallengeNameType .deviceSrpAuth
399
413
..challengeResponses.addAll ({
400
414
CognitoConstants .challengeParamUsername: cognitoUsername,
@@ -416,8 +430,9 @@ final class SignInStateMachine
416
430
b
417
431
..deviceSecrets = _user.deviceSecrets! .build ()
418
432
..initResult = _initResult
419
- ..clientId = config.appClientId
420
- ..clientSecret = config.appClientSecret
433
+ ..clientId = _authOutputs.userPoolClientId
434
+ // ignore: invalid_use_of_internal_member
435
+ ..clientSecret = _authOutputs.appClientSecret
421
436
..challengeParameters = BuiltMap (_publicChallengeParameters);
422
437
});
423
438
worker.sink.add (workerMessage);
@@ -432,7 +447,7 @@ final class SignInStateMachine
432
447
_enableMfaType = MfaType .sms;
433
448
return RespondToAuthChallengeRequest .build ((b) {
434
449
b
435
- ..clientId = config.appClientId
450
+ ..clientId = _authOutputs.userPoolClientId
436
451
..challengeName = _challengeName
437
452
..challengeResponses.addAll ({
438
453
CognitoConstants .challengeParamUsername: cognitoUsername,
@@ -449,7 +464,7 @@ final class SignInStateMachine
449
464
) async {
450
465
return RespondToAuthChallengeRequest .build ((b) {
451
466
b
452
- ..clientId = config.appClientId
467
+ ..clientId = _authOutputs.userPoolClientId
453
468
..challengeName = _challengeName
454
469
..challengeResponses.addAll ({
455
470
CognitoConstants .challengeParamUsername: cognitoUsername,
@@ -490,7 +505,7 @@ final class SignInStateMachine
490
505
return InitiateAuthRequest .build ((b) {
491
506
b
492
507
..authFlow = AuthFlowType .userSrpAuth
493
- ..clientId = config.appClientId
508
+ ..clientId = _authOutputs.userPoolClientId
494
509
..authParameters.addAll ({
495
510
CognitoConstants .challengeParamUsername: providedUsername,
496
511
CognitoConstants .challengeParamSrpA:
@@ -509,7 +524,7 @@ final class SignInStateMachine
509
524
return InitiateAuthRequest .build ((b) {
510
525
b
511
526
..authFlow = AuthFlowType .userPasswordAuth
512
- ..clientId = config.appClientId
527
+ ..clientId = _authOutputs.userPoolClientId
513
528
..authParameters.addAll ({
514
529
CognitoConstants .challengeParamUsername: providedUsername,
515
530
CognitoConstants .challengeParamPassword: password,
@@ -562,7 +577,7 @@ final class SignInStateMachine
562
577
..authFlow = AuthFlowType .customAuth
563
578
..authParameters[CognitoConstants .challengeParamUsername] =
564
579
providedUsername
565
- ..clientId = config.appClientId
580
+ ..clientId = _authOutputs.userPoolClientId
566
581
..clientMetadata.addAll (event.clientMetadata);
567
582
});
568
583
}
@@ -641,7 +656,7 @@ final class SignInStateMachine
641
656
// Must be the session from `VerifySoftwareToken`
642
657
CognitoConstants .challengeParamSession: _session! ,
643
658
})
644
- ..clientId = config.appClientId
659
+ ..clientId = _authOutputs.userPoolClientId
645
660
..clientMetadata.addAll (event.clientMetadata);
646
661
});
647
662
}
@@ -663,7 +678,7 @@ final class SignInStateMachine
663
678
_ => throw ArgumentError ('Must be either SMS or TOTP' ),
664
679
},
665
680
})
666
- ..clientId = config.appClientId
681
+ ..clientId = _authOutputs.userPoolClientId
667
682
..clientMetadata.addAll (event.clientMetadata);
668
683
});
669
684
}
@@ -681,7 +696,7 @@ final class SignInStateMachine
681
696
CognitoConstants .challengeParamUsername: cognitoUsername,
682
697
CognitoConstants .challengeParamSoftwareTokenMfaCode: event.answer,
683
698
})
684
- ..clientId = config.appClientId
699
+ ..clientId = _authOutputs.userPoolClientId
685
700
..clientMetadata.addAll (event.clientMetadata);
686
701
});
687
702
}
@@ -789,11 +804,12 @@ final class SignInStateMachine
789
804
initRequest = initRequest.rebuild ((b) {
790
805
b.analyticsMetadata = get <AnalyticsMetadataType >()? .toBuilder ();
791
806
792
- if (config.appClientSecret case final appClientSecret? ) {
807
+ // ignore: invalid_use_of_internal_member
808
+ if (_authOutputs.appClientSecret case final appClientSecret? ) {
793
809
b.authParameters[CognitoConstants .challengeParamSecretHash] =
794
810
computeSecretHash (
795
811
providedUsername,
796
- config.appClientId ,
812
+ _authOutputs.userPoolClientId ! ,
797
813
appClientSecret,
798
814
);
799
815
}
@@ -1003,11 +1019,12 @@ final class SignInStateMachine
1003
1019
..clientMetadata.replace (event? .clientMetadata ?? const {})
1004
1020
..analyticsMetadata = get <AnalyticsMetadataType >()? .toBuilder ();
1005
1021
1006
- if (config.appClientSecret case final appClientSecret? ) {
1022
+ // ignore: invalid_use_of_internal_member
1023
+ if (_authOutputs.appClientSecret case final appClientSecret? ) {
1007
1024
b.challengeResponses[CognitoConstants .challengeParamSecretHash] ?? =
1008
1025
computeSecretHash (
1009
1026
cognitoUsername,
1010
- config.appClientId ,
1027
+ _authOutputs.userPoolClientId ! ,
1011
1028
appClientSecret,
1012
1029
);
1013
1030
}
0 commit comments