@@ -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' ;
@@ -59,12 +61,20 @@ final class SignInStateMachine
59
61
/// Parameters to the flow.
60
62
late SignInParameters parameters;
61
63
62
- /// The configured user pool.
63
- late final CognitoUserPoolConfig config = expect ();
64
-
65
64
/// The configured identity pool.
65
+ // TODO(nikahsn): remove after refactoring CognitoIdentityPoolKeys to use
66
+ // AmplifyOutputs type
66
67
CognitoIdentityCredentialsProvider ? get identityPoolConfig => get ();
67
68
69
+ AuthOutputs get _authOutputs {
70
+ final authOutputs = get <AuthOutputs >();
71
+ if (authOutputs? .userPoolId == null ||
72
+ authOutputs? .userPoolClientId == null ) {
73
+ throw const InvalidAccountTypeException .noUserPool ();
74
+ }
75
+ return authOutputs! ;
76
+ }
77
+
68
78
/// The Cognito Identity Provider service client.
69
79
late final CognitoIdentityProviderClient cognitoIdentityProvider = expect ();
70
80
@@ -344,7 +354,7 @@ final class SignInStateMachine
344
354
if (_user.deviceSecrets? .deviceKey case final deviceKey? )
345
355
CognitoConstants .challengeParamDeviceKey: deviceKey,
346
356
})
347
- ..clientId = config.appClientId
357
+ ..clientId = _authOutputs.userPoolClientId
348
358
..clientMetadata.addAll (event.clientMetadata)
349
359
..analyticsMetadata = get <AnalyticsMetadataType >()? .toBuilder (),
350
360
);
@@ -370,9 +380,10 @@ final class SignInStateMachine
370
380
final workerMessage = SrpPasswordVerifierMessage ((b) {
371
381
b
372
382
..initResult = initResult
373
- ..clientId = config.appClientId
374
- ..clientSecret = config.appClientSecret
375
- ..poolId = config.poolId
383
+ ..clientId = _authOutputs.userPoolClientId
384
+ // ignore: invalid_use_of_internal_member
385
+ ..clientSecret = _authOutputs.appClientSecret
386
+ ..poolId = _authOutputs.userPoolId
376
387
..deviceKey = _user.deviceSecrets? .deviceKey
377
388
..challengeParameters = BuiltMap (_publicChallengeParameters)
378
389
..parameters = SignInParameters (
@@ -394,7 +405,7 @@ final class SignInStateMachine
394
405
_initResult ?? = await _initSrp ();
395
406
return RespondToAuthChallengeRequest .build ((b) {
396
407
b
397
- ..clientId = config.appClientId
408
+ ..clientId = _authOutputs.userPoolClientId
398
409
..challengeName = ChallengeNameType .deviceSrpAuth
399
410
..challengeResponses.addAll ({
400
411
CognitoConstants .challengeParamUsername: cognitoUsername,
@@ -416,8 +427,9 @@ final class SignInStateMachine
416
427
b
417
428
..deviceSecrets = _user.deviceSecrets! .build ()
418
429
..initResult = _initResult
419
- ..clientId = config.appClientId
420
- ..clientSecret = config.appClientSecret
430
+ ..clientId = _authOutputs.userPoolClientId
431
+ // ignore: invalid_use_of_internal_member
432
+ ..clientSecret = _authOutputs.appClientSecret
421
433
..challengeParameters = BuiltMap (_publicChallengeParameters);
422
434
});
423
435
worker.sink.add (workerMessage);
@@ -432,7 +444,7 @@ final class SignInStateMachine
432
444
_enableMfaType = MfaType .sms;
433
445
return RespondToAuthChallengeRequest .build ((b) {
434
446
b
435
- ..clientId = config.appClientId
447
+ ..clientId = _authOutputs.userPoolClientId
436
448
..challengeName = _challengeName
437
449
..challengeResponses.addAll ({
438
450
CognitoConstants .challengeParamUsername: cognitoUsername,
@@ -449,7 +461,7 @@ final class SignInStateMachine
449
461
) async {
450
462
return RespondToAuthChallengeRequest .build ((b) {
451
463
b
452
- ..clientId = config.appClientId
464
+ ..clientId = _authOutputs.userPoolClientId
453
465
..challengeName = _challengeName
454
466
..challengeResponses.addAll ({
455
467
CognitoConstants .challengeParamUsername: cognitoUsername,
@@ -490,7 +502,7 @@ final class SignInStateMachine
490
502
return InitiateAuthRequest .build ((b) {
491
503
b
492
504
..authFlow = AuthFlowType .userSrpAuth
493
- ..clientId = config.appClientId
505
+ ..clientId = _authOutputs.userPoolClientId
494
506
..authParameters.addAll ({
495
507
CognitoConstants .challengeParamUsername: providedUsername,
496
508
CognitoConstants .challengeParamSrpA:
@@ -509,7 +521,7 @@ final class SignInStateMachine
509
521
return InitiateAuthRequest .build ((b) {
510
522
b
511
523
..authFlow = AuthFlowType .userPasswordAuth
512
- ..clientId = config.appClientId
524
+ ..clientId = _authOutputs.userPoolClientId
513
525
..authParameters.addAll ({
514
526
CognitoConstants .challengeParamUsername: providedUsername,
515
527
CognitoConstants .challengeParamPassword: password,
@@ -562,7 +574,7 @@ final class SignInStateMachine
562
574
..authFlow = AuthFlowType .customAuth
563
575
..authParameters[CognitoConstants .challengeParamUsername] =
564
576
providedUsername
565
- ..clientId = config.appClientId
577
+ ..clientId = _authOutputs.userPoolClientId
566
578
..clientMetadata.addAll (event.clientMetadata);
567
579
});
568
580
}
@@ -641,7 +653,7 @@ final class SignInStateMachine
641
653
// Must be the session from `VerifySoftwareToken`
642
654
CognitoConstants .challengeParamSession: _session! ,
643
655
})
644
- ..clientId = config.appClientId
656
+ ..clientId = _authOutputs.userPoolClientId
645
657
..clientMetadata.addAll (event.clientMetadata);
646
658
});
647
659
}
@@ -663,7 +675,7 @@ final class SignInStateMachine
663
675
_ => throw ArgumentError ('Must be either SMS or TOTP' ),
664
676
},
665
677
})
666
- ..clientId = config.appClientId
678
+ ..clientId = _authOutputs.userPoolClientId
667
679
..clientMetadata.addAll (event.clientMetadata);
668
680
});
669
681
}
@@ -681,7 +693,7 @@ final class SignInStateMachine
681
693
CognitoConstants .challengeParamUsername: cognitoUsername,
682
694
CognitoConstants .challengeParamSoftwareTokenMfaCode: event.answer,
683
695
})
684
- ..clientId = config.appClientId
696
+ ..clientId = _authOutputs.userPoolClientId
685
697
..clientMetadata.addAll (event.clientMetadata);
686
698
});
687
699
}
@@ -789,11 +801,12 @@ final class SignInStateMachine
789
801
initRequest = initRequest.rebuild ((b) {
790
802
b.analyticsMetadata = get <AnalyticsMetadataType >()? .toBuilder ();
791
803
792
- if (config.appClientSecret case final appClientSecret? ) {
804
+ // ignore: invalid_use_of_internal_member
805
+ if (_authOutputs.appClientSecret case final appClientSecret? ) {
793
806
b.authParameters[CognitoConstants .challengeParamSecretHash] =
794
807
computeSecretHash (
795
808
providedUsername,
796
- config.appClientId ,
809
+ _authOutputs.userPoolClientId ! ,
797
810
appClientSecret,
798
811
);
799
812
}
@@ -1003,11 +1016,12 @@ final class SignInStateMachine
1003
1016
..clientMetadata.replace (event? .clientMetadata ?? const {})
1004
1017
..analyticsMetadata = get <AnalyticsMetadataType >()? .toBuilder ();
1005
1018
1006
- if (config.appClientSecret case final appClientSecret? ) {
1019
+ // ignore: invalid_use_of_internal_member
1020
+ if (_authOutputs.appClientSecret case final appClientSecret? ) {
1007
1021
b.challengeResponses[CognitoConstants .challengeParamSecretHash] ?? =
1008
1022
computeSecretHash (
1009
1023
cognitoUsername,
1010
- config.appClientId ,
1024
+ _authOutputs.userPoolClientId ! ,
1011
1025
appClientSecret,
1012
1026
);
1013
1027
}
0 commit comments