Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(auth): asf context data provider to use AuthOutputs instead of CognitoUserPoolConfig #5290

Merged
merged 1 commit into from
Aug 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import 'package:amplify_auth_cognito_dart/src/asf/asf_worker.dart';
import 'package:amplify_auth_cognito_dart/src/credentials/cognito_keys.dart';
import 'package:amplify_auth_cognito_dart/src/sdk/cognito_identity_provider.dart';
import 'package:amplify_core/amplify_core.dart';
// ignore: implementation_imports
import 'package:amplify_core/src/config/amplify_outputs/auth/auth_outputs.dart';
import 'package:amplify_secure_storage_dart/amplify_secure_storage_dart.dart';
import 'package:async/async.dart';

Expand All @@ -22,14 +24,14 @@ final class ASFContextDataProvider with AWSDebuggable, AWSLoggerMixin {
/// Retrieves context data as required for advanced security features (ASF).
ASFDeviceInfoCollector get _platform => _dependencyManager.getOrCreate();

/// The Cognito user pool configuration.
CognitoUserPoolConfig? get _userPoolConfig => _dependencyManager.get();
/// The Auth configuration.
AuthOutputs? get _authOutputs => _dependencyManager.get();

SecureStorageInterface get _secureStorage => _dependencyManager.expect();

/// The unique device ID (`DeviceID`).
Future<String> get _deviceId async {
final userPoolKeys = CognitoUserPoolKeys(_userPoolConfig!.appClientId);
final userPoolKeys = CognitoUserPoolKeys(_authOutputs!.userPoolClientId!);
var deviceId = await _secureStorage.read(
key: userPoolKeys[CognitoUserPoolKey.asfDeviceId],
);
Expand Down Expand Up @@ -73,15 +75,16 @@ final class ASFContextDataProvider with AWSDebuggable, AWSLoggerMixin {
/// Builds the [UserContextDataType] object which can be attached to SDK
/// calls.
Future<UserContextDataType?> buildRequestData(String username) async {
final userPoolConfig = _userPoolConfig;
if (userPoolConfig == null) {
if (_authOutputs == null ||
_authOutputs?.userPoolClientId == null ||
_authOutputs?.userPoolId == null) {
return null;
}
final nativeContextData = await _platform.getNativeContextData();
logger.verbose('Got native context data: $nativeContextData');
final deviceId = await _deviceId;
final userPoolId = userPoolConfig.poolId;
final clientId = userPoolConfig.appClientId;
final userPoolId = _authOutputs!.userPoolId!;
final clientId = _authOutputs!.userPoolClientId!;

final request = ASFWorkerRequest(
userPoolId: userPoolId,
Expand Down
Loading