diff --git a/packages/auth/amplify_auth_cognito/example/integration_test/native_auth_bridge_test.dart b/packages/auth/amplify_auth_cognito/example/integration_test/native_auth_bridge_test.dart index 6af168b566..7ff9a0ca6c 100644 --- a/packages/auth/amplify_auth_cognito/example/integration_test/native_auth_bridge_test.dart +++ b/packages/auth/amplify_auth_cognito/example/integration_test/native_auth_bridge_test.dart @@ -11,6 +11,7 @@ import 'package:amplify_auth_cognito/src/native_auth_plugin.g.dart'; import 'package:amplify_auth_cognito_dart/src/state/state.dart'; import 'package:amplify_auth_cognito_test/amplify_auth_cognito_test.dart'; import 'package:amplify_auth_integration_test/amplify_auth_integration_test.dart'; +import 'package:amplify_core/src/config/amplify_outputs/auth/auth_outputs.dart'; import 'package:amplify_flutter/amplify_flutter.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:http/http.dart' as http; @@ -34,7 +35,7 @@ void main() { setUp(() async { dependencyManager = DependencyManager() - ..addInstance(hostedUiConfig) + ..addInstance(mockConfig.auth!) ..addInstance(MockSecureStorage()) ..addInstance( MockClient((request) { @@ -58,7 +59,7 @@ void main() { argPreferprivatesession, argBrowserpackagename, ) async { - expect(argUrl, contains(hostedUiConfig.webDomain)); + expect(argUrl, contains(mockConfig.auth?.oauth?.domain)); expect(argCallbackurlscheme, testUrlScheme); expect(argPreferprivatesession, isFalse); expect(argBrowserpackagename, browserPackage); @@ -86,7 +87,7 @@ void main() { argPreferprivatesession, argBrowserpackagename, ) async { - expect(argUrl, contains(hostedUiConfig.webDomain)); + expect(argUrl, contains(mockConfig.auth?.oauth?.domain)); expect(argCallbackurlscheme, testUrlScheme); expect(argPreferprivatesession, isFalse); expect(argBrowserpackagename, browserPackage); diff --git a/packages/auth/amplify_auth_cognito/lib/src/flows/hosted_ui/hosted_ui_platform_flutter.dart b/packages/auth/amplify_auth_cognito/lib/src/flows/hosted_ui/hosted_ui_platform_flutter.dart index f108e5110e..091770841b 100644 --- a/packages/auth/amplify_auth_cognito/lib/src/flows/hosted_ui/hosted_ui_platform_flutter.dart +++ b/packages/auth/amplify_auth_cognito/lib/src/flows/hosted_ui/hosted_ui_platform_flutter.dart @@ -58,10 +58,10 @@ class HostedUiPlatformImpl extends io.HostedUiPlatformImpl { if (!_isMobile) { return super.signInRedirectUri; } - return config.signInRedirectUris.firstWhere( - (uri) => uri.scheme != 'https' && uri.scheme != 'http', - orElse: () => _noSuitableRedirect(signIn: true), - ); + return authOutputs.oauth!.redirectSignInUri.map(Uri.parse).firstWhere( + (uri) => uri.scheme != 'https' && uri.scheme != 'http', + orElse: () => _noSuitableRedirect(signIn: true), + ); } @override @@ -69,10 +69,10 @@ class HostedUiPlatformImpl extends io.HostedUiPlatformImpl { if (!_isMobile) { return super.signOutRedirectUri; } - return config.signOutRedirectUris.firstWhere( - (uri) => uri.scheme != 'https' && uri.scheme != 'http', - orElse: () => _noSuitableRedirect(signIn: false), - ); + return authOutputs.oauth!.redirectSignOutUri.map(Uri.parse).firstWhere( + (uri) => uri.scheme != 'https' && uri.scheme != 'http', + orElse: () => _noSuitableRedirect(signIn: false), + ); } @override diff --git a/packages/auth/amplify_auth_cognito/test/hosted_ui_platform_flutter_test.dart b/packages/auth/amplify_auth_cognito/test/hosted_ui_platform_flutter_test.dart index 728f725c04..92546d2163 100644 --- a/packages/auth/amplify_auth_cognito/test/hosted_ui_platform_flutter_test.dart +++ b/packages/auth/amplify_auth_cognito/test/hosted_ui_platform_flutter_test.dart @@ -26,7 +26,7 @@ void main() { setUp(() async { secureStorage = MockSecureStorage(); dependencyManager = DependencyManager() - ..addInstance(hostedUiConfig) + ..addInstance(mockConfig.auth!) ..addInstance(secureStorage) ..addInstance(ThrowingNativeBridge()); plugin = AmplifyAuthCognito() diff --git a/packages/auth/amplify_auth_cognito_dart/lib/src/flows/hosted_ui/hosted_ui_config.dart b/packages/auth/amplify_auth_cognito_dart/lib/src/flows/hosted_ui/hosted_ui_config.dart index ac010eb317..1bde8b6630 100644 --- a/packages/auth/amplify_auth_cognito_dart/lib/src/flows/hosted_ui/hosted_ui_config.dart +++ b/packages/auth/amplify_auth_cognito_dart/lib/src/flows/hosted_ui/hosted_ui_config.dart @@ -2,32 +2,23 @@ // SPDX-License-Identifier: Apache-2.0 import 'package:amplify_core/amplify_core.dart'; - -/// Configuration helpers for [CognitoUserPoolConfig]. -extension HostedUiJwks on CognitoUserPoolConfig { - /// The JSON Web Key (JWK) URI. - /// - /// References: - /// - https://docs.aws.amazon.com/cognito/latest/developerguide/amazon-cognito-user-pools-using-tokens-verifying-a-jwt.html - Uri get jwksUri => Uri.parse( - 'https://cognito-idp.$region.amazonaws.com/$poolId/.well-known/jwks.json', - ); -} +// ignore: implementation_imports +import 'package:amplify_core/src/config/amplify_outputs/auth/oauth_outputs.dart'; /// Configuration helpers for [CognitoOAuthConfig]. /// /// [Reference](https://docs.aws.amazon.com/cognito/latest/developerguide/cognito-userpools-server-contract-reference.html) -extension HostedUiConfig on CognitoOAuthConfig { - /// The parsed [webDomain] URI. +extension HostedUiConfig on OAuthOutputs { + /// The parsed [domain] URI. /// - /// If [webDomain] specifies a scheme, it is honored in requests in the same + /// If [domain] specifies a scheme, it is honored in requests in the same /// way that it is honored for [signInUri], [tokenUri], and [signOutUri]. If - /// no scheme is specified, it defaults to `https` and [webDomain] is + /// no scheme is specified, it defaults to `https` and [domain] is /// interpreted as a host string. Uri get _webDomain { - final uri = Uri.parse(webDomain); + final uri = Uri.parse(domain); if (uri.hasScheme) return uri; - return Uri(scheme: 'https', host: webDomain); + return Uri(scheme: 'https', host: domain); } /// The sign in URI. @@ -37,7 +28,9 @@ extension HostedUiConfig on CognitoOAuthConfig { /// - https://docs.aws.amazon.com/cognito/latest/developerguide/login-endpoint.html Uri signInUri([AuthProvider? provider]) { Uri baseUri; + // ignore: invalid_use_of_internal_member if (this.signInUri != null) { + // ignore: invalid_use_of_internal_member baseUri = Uri.parse(this.signInUri!); } else { baseUri = _webDomain.replace(path: '/oauth2/authorize'); @@ -45,6 +38,7 @@ extension HostedUiConfig on CognitoOAuthConfig { return baseUri.replace( queryParameters: { if (provider != null) 'identity_provider': provider.uriParameter, + // ignore: invalid_use_of_internal_member ...?signInUriQueryParameters, }, ); @@ -54,12 +48,13 @@ extension HostedUiConfig on CognitoOAuthConfig { /// /// References: /// - https://docs.aws.amazon.com/cognito/latest/developerguide/logout-endpoint.html - Uri get signOutUri { + Uri signOutUri(String userPoolClientId) { return _webDomain.replace( path: '/logout', queryParameters: { + // ignore: invalid_use_of_internal_member ...?signOutUriQueryParameters, - 'client_id': appClientId, + 'client_id': userPoolClientId, }, ); } @@ -67,12 +62,12 @@ extension HostedUiConfig on CognitoOAuthConfig { /// The sign in redirect URI to use. /// /// Throws a [StateError] if there are no URIs registered. - Uri get signInRedirectUri => signInRedirectUris.first; + Uri get signInRedirectUri => Uri.parse(redirectSignInUri.first); /// The sign out redirect URI to use. /// /// Throws a [StateError] if there are no URIs registered. - Uri get signOutRedirectUri => signOutRedirectUris.first; + Uri get signOutRedirectUri => Uri.parse(redirectSignOutUri.first); /// The `token` URI. /// @@ -80,25 +75,16 @@ extension HostedUiConfig on CognitoOAuthConfig { /// - https://docs.aws.amazon.com/cognito/latest/developerguide/token-endpoint.html Uri get tokenUri { Uri baseUri; + // ignore: invalid_use_of_internal_member if (this.tokenUri != null) { + // ignore: invalid_use_of_internal_member baseUri = Uri.parse(this.tokenUri!); } else { baseUri = _webDomain.replace(path: '/oauth2/token'); } return baseUri.replace( + // ignore: invalid_use_of_internal_member queryParameters: tokenUriQueryParameters, ); } - - /// The `revoke` URI. - /// - /// References: - /// - https://docs.aws.amazon.com/cognito/latest/developerguide/revocation-endpoint.html - Uri get revocationUri => _webDomain.replace(path: '/oauth2/revoke'); - - /// The `userinfo` URI. - /// - /// References: - /// - https://docs.aws.amazon.com/cognito/latest/developerguide/userinfo-endpoint.html - Uri get userInfoUri => _webDomain.replace(path: '/oauth2/userInfo'); } diff --git a/packages/auth/amplify_auth_cognito_dart/lib/src/flows/hosted_ui/hosted_ui_platform.dart b/packages/auth/amplify_auth_cognito_dart/lib/src/flows/hosted_ui/hosted_ui_platform.dart index db19c92adc..4d1a33ca63 100644 --- a/packages/auth/amplify_auth_cognito_dart/lib/src/flows/hosted_ui/hosted_ui_platform.dart +++ b/packages/auth/amplify_auth_cognito_dart/lib/src/flows/hosted_ui/hosted_ui_platform.dart @@ -13,6 +13,10 @@ import 'package:amplify_auth_cognito_dart/src/flows/hosted_ui/hosted_ui_platform import 'package:amplify_auth_cognito_dart/src/model/hosted_ui/oauth_parameters.dart'; import 'package:amplify_auth_cognito_dart/src/state/state.dart'; import 'package:amplify_core/amplify_core.dart'; +// ignore: implementation_imports +import 'package:amplify_core/src/config/amplify_outputs/auth/auth_outputs.dart'; +// ignore: implementation_imports +import 'package:amplify_core/src/config/amplify_outputs/auth/oauth_outputs.dart'; import 'package:amplify_secure_storage_dart/amplify_secure_storage_dart.dart'; import 'package:http/http.dart' as http; import 'package:meta/meta.dart'; @@ -35,12 +39,18 @@ abstract class HostedUiPlatform implements Closeable { @protected HostedUiPlatform.protected(this.dependencyManager); - /// The Hosted UI configuration. + /// The Auth configuration. @protected - CognitoOAuthConfig get config => dependencyManager.expect(); + AuthOutputs get authOutputs { + final authOutputs = dependencyManager.get(); + if (authOutputs?.oauth == null || authOutputs?.userPoolClientId == null) { + throw const InvalidAccountTypeException.noUserPool(); + } + return authOutputs!; + } /// The Hosted UI storage keys. - late final HostedUiKeys _keys = HostedUiKeys(config.appClientId); + late final HostedUiKeys _keys = HostedUiKeys(authOutputs.userPoolClientId!); /// The secure storage plugin. SecureStorageInterface get _secureStorage => dependencyManager.getOrCreate(); @@ -114,14 +124,16 @@ abstract class HostedUiPlatform implements Closeable { ); _authCodeGrant = createGrant( - config, + authOutputs.oauth!, authOutputs.userPoolClientId!, + // ignore: invalid_use_of_internal_member + appClientSecret: authOutputs.appClientSecret, codeVerifier: codeVerifier, httpClient: httpClient, provider: provider, ); final uri = _authCodeGrant!.getAuthorizationUrl( redirectUri ?? signInRedirectUri, - scopes: config.scopes, + scopes: authOutputs.oauth?.scopes, state: state, ); @@ -137,7 +149,8 @@ abstract class HostedUiPlatform implements Closeable { @visibleForTesting @nonVirtual Uri getSignOutUri({Uri? redirectUri}) { - final signOutUri = HostedUiConfig(config).signOutUri; + final signOutUri = HostedUiConfig(authOutputs.oauth!) + .signOutUri(authOutputs.userPoolClientId!); return signOutUri.replace( queryParameters: { @@ -152,16 +165,18 @@ abstract class HostedUiPlatform implements Closeable { @visibleForTesting @nonVirtual oauth2.AuthorizationCodeGrant createGrant( - CognitoOAuthConfig config, { + OAuthOutputs oauthOutputs, + String userPoolClientId, { + String? appClientSecret, AuthProvider? provider, String? codeVerifier, http.Client? httpClient, }) { return oauth2.AuthorizationCodeGrant( - config.appClientId, - HostedUiConfig(config).signInUri(provider), - HostedUiConfig(config).tokenUri, - secret: config.appClientSecret, + userPoolClientId, + HostedUiConfig(authOutputs.oauth!).signInUri(provider), + HostedUiConfig(authOutputs.oauth!).tokenUri, + secret: appClientSecret, httpClient: httpClient, codeVerifier: codeVerifier, @@ -177,13 +192,15 @@ abstract class HostedUiPlatform implements Closeable { @visibleForTesting @nonVirtual oauth2.AuthorizationCodeGrant restoreGrant( - CognitoOAuthConfig config, { + OAuthOutputs oauthOutputs, + String userPoolClientId, { required String state, required String codeVerifier, http.Client? httpClient, }) { final grant = createGrant( - config, + oauthOutputs, + userPoolClientId, codeVerifier: codeVerifier, httpClient: httpClient, ); @@ -192,7 +209,7 @@ abstract class HostedUiPlatform implements Closeable { // Advances the internal state. ..getAuthorizationUrl( signInRedirectUri, - scopes: config.scopes, + scopes: oauthOutputs.scopes, state: state, ); } @@ -247,7 +264,8 @@ abstract class HostedUiPlatform implements Closeable { final parameters = dependencyManager.get(); if (parameters != null) { authCodeGrant = restoreGrant( - config, + authOutputs.oauth!, + authOutputs.userPoolClientId!, state: state, codeVerifier: codeVerifier, httpClient: httpClient, diff --git a/packages/auth/amplify_auth_cognito_dart/lib/src/flows/hosted_ui/hosted_ui_platform_html.dart b/packages/auth/amplify_auth_cognito_dart/lib/src/flows/hosted_ui/hosted_ui_platform_html.dart index f4bfaafa6e..159029e6cc 100644 --- a/packages/auth/amplify_auth_cognito_dart/lib/src/flows/hosted_ui/hosted_ui_platform_html.dart +++ b/packages/auth/amplify_auth_cognito_dart/lib/src/flows/hosted_ui/hosted_ui_platform_html.dart @@ -3,7 +3,6 @@ import 'package:amplify_auth_cognito_dart/amplify_auth_cognito_dart.dart'; import 'package:amplify_auth_cognito_dart/src/flows/hosted_ui/hosted_ui_platform.dart'; -import 'package:amplify_core/amplify_core.dart'; // ignore: implementation_imports import 'package:aws_common/src/js/common.dart'; import 'package:path/path.dart' show url; @@ -31,15 +30,19 @@ class HostedUiPlatformImpl extends HostedUiPlatform { } @override - Uri get signInRedirectUri => config.signInRedirectUris.firstWhere( - (uri) => uri.toString().startsWith(_baseUrl), - orElse: () => _noSuitableRedirect(signIn: true), + Uri get signInRedirectUri => Uri.parse( + authOutputs.oauth!.redirectSignInUri.firstWhere( + (uri) => uri.startsWith(_baseUrl), + orElse: () => _noSuitableRedirect(signIn: true), + ), ); @override - Uri get signOutRedirectUri => config.signOutRedirectUris.firstWhere( - (uri) => uri.toString().startsWith(_baseUrl), - orElse: () => _noSuitableRedirect(signIn: false), + Uri get signOutRedirectUri => Uri.parse( + authOutputs.oauth!.redirectSignOutUri.firstWhere( + (uri) => uri.startsWith(_baseUrl), + orElse: () => _noSuitableRedirect(signIn: false), + ), ); /// Launches the given URL. diff --git a/packages/auth/amplify_auth_cognito_dart/lib/src/flows/hosted_ui/hosted_ui_platform_io.dart b/packages/auth/amplify_auth_cognito_dart/lib/src/flows/hosted_ui/hosted_ui_platform_io.dart index aca34f8f5c..c05eb28d6e 100644 --- a/packages/auth/amplify_auth_cognito_dart/lib/src/flows/hosted_ui/hosted_ui_platform_io.dart +++ b/packages/auth/amplify_auth_cognito_dart/lib/src/flows/hosted_ui/hosted_ui_platform_io.dart @@ -98,7 +98,11 @@ class HostedUiPlatformImpl extends HostedUiPlatform { } @override - Uri get signInRedirectUri => config.signInRedirectUris.firstWhere( + Uri get signInRedirectUri => authOutputs.oauth!.redirectSignInUri + .map( + Uri.parse, + ) + .firstWhere( (uri) => uri.scheme == 'http' && (uri.host == 'localhost' || uri.host == '127.0.0.1'), @@ -106,7 +110,11 @@ class HostedUiPlatformImpl extends HostedUiPlatform { ); @override - Uri get signOutRedirectUri => config.signOutRedirectUris.firstWhere( + Uri get signOutRedirectUri => authOutputs.oauth!.redirectSignOutUri + .map( + Uri.parse, + ) + .firstWhere( (uri) => uri.scheme == 'http' && (uri.host == 'localhost' || uri.host == '127.0.0.1'), @@ -202,11 +210,15 @@ class HostedUiPlatformImpl extends HostedUiPlatform { required CognitoSignInWithWebUIPluginOptions options, AuthProvider? provider, }) async { - final signInUris = config.signInRedirectUris.where( - (uri) => - uri.scheme == 'http' && - (uri.host == 'localhost' || uri.host == '127.0.0.1'), - ); + final signInUris = authOutputs.oauth!.redirectSignInUri + .map( + Uri.parse, + ) + .where( + (uri) => + uri.scheme == 'http' && + (uri.host == 'localhost' || uri.host == '127.0.0.1'), + ); if (signInUris.isEmpty) { _noSuitableRedirect(signIn: true); } @@ -274,11 +286,15 @@ class HostedUiPlatformImpl extends HostedUiPlatform { Future signOut({ required CognitoSignInWithWebUIPluginOptions options, }) async { - final signOutUris = config.signOutRedirectUris.where( - (uri) => - uri.scheme == 'http' && - (uri.host == 'localhost' || uri.host == '127.0.0.1'), - ); + final signOutUris = authOutputs.oauth!.redirectSignOutUri + .map( + Uri.parse, + ) + .where( + (uri) => + uri.scheme == 'http' && + (uri.host == 'localhost' || uri.host == '127.0.0.1'), + ); if (signOutUris.isEmpty) { _noSuitableRedirect(signIn: false); } diff --git a/packages/auth/amplify_auth_cognito_test/lib/common/mock_config.dart b/packages/auth/amplify_auth_cognito_test/lib/common/mock_config.dart index 48a9407ac4..1288d86930 100644 --- a/packages/auth/amplify_auth_cognito_test/lib/common/mock_config.dart +++ b/packages/auth/amplify_auth_cognito_test/lib/common/mock_config.dart @@ -131,10 +131,9 @@ final mockConfigWithPinpoint = AmplifyOutputs.fromJson( jsonDecode(amplifyConfigWithAnalytics) as Map, ); -final hostedUiConfig = CognitoOAuthConfig.fromAuthOutputs(mockConfig.auth!); final authConfig = AuthConfiguration.fromAmplifyOutputs(mockConfig); +// TODO(nikahsn): remove after refactoring DeviceMetadataRepository final userPoolConfig = authConfig.userPoolConfig!; -final identityPoolConfig = authConfig.identityPoolConfig!; final userPoolKeys = CognitoUserPoolKeys(mockConfig.auth!.userPoolClientId!); final deviceKeys = CognitoDeviceKeys(mockConfig.auth!.userPoolClientId!, userSub); diff --git a/packages/auth/amplify_auth_cognito_test/lib/common/mock_hosted_ui.dart b/packages/auth/amplify_auth_cognito_test/lib/common/mock_hosted_ui.dart index a877359483..70103e1ccf 100644 --- a/packages/auth/amplify_auth_cognito_test/lib/common/mock_hosted_ui.dart +++ b/packages/auth/amplify_auth_cognito_test/lib/common/mock_hosted_ui.dart @@ -57,8 +57,10 @@ class MockHostedUiPlatform extends HostedUiPlatformImpl { _signOut(this, options); @override - Uri get signInRedirectUri => config.signInRedirectUris.first; + Uri get signInRedirectUri => + Uri.parse(authOutputs.oauth!.redirectSignInUri.first); @override - Uri get signOutRedirectUri => config.signOutRedirectUris.first; + Uri get signOutRedirectUri => + Uri.parse(authOutputs.oauth!.redirectSignOutUri.first); } diff --git a/packages/auth/amplify_auth_cognito_test/test/flows/hostedui/hosted_ui_platform_io_test.dart b/packages/auth/amplify_auth_cognito_test/test/flows/hostedui/hosted_ui_platform_io_test.dart index 2e07e4e636..20efc8786b 100644 --- a/packages/auth/amplify_auth_cognito_test/test/flows/hostedui/hosted_ui_platform_io_test.dart +++ b/packages/auth/amplify_auth_cognito_test/test/flows/hostedui/hosted_ui_platform_io_test.dart @@ -135,14 +135,12 @@ void main() { ); dependencyManager ..addInstance(client) - ..addInstance(mockConfig) - ..addInstance(hostedUiConfig) + ..addInstance(mockConfig.auth!) ..addInstance>(dispatcher); final hostedUiPlatform = MockHostedUiPlatform(dependencyManager); final redirect = Uri.parse( - hostedUiConfig.signInRedirectUri - .split(',') + mockConfig.auth!.oauth!.redirectSignInUri .firstWhere((uri) => uri.contains('localhost')), ); expect(hostedUiPlatform.signInRedirectUri, redirect); diff --git a/packages/auth/amplify_auth_cognito_test/test/flows/hostedui/hosted_ui_platform_test.dart b/packages/auth/amplify_auth_cognito_test/test/flows/hostedui/hosted_ui_platform_test.dart index c2eb600cdd..bc32a16697 100644 --- a/packages/auth/amplify_auth_cognito_test/test/flows/hostedui/hosted_ui_platform_test.dart +++ b/packages/auth/amplify_auth_cognito_test/test/flows/hostedui/hosted_ui_platform_test.dart @@ -26,7 +26,7 @@ void main() { late SecureStorageInterface secureStorage; late HostedUiPlatform platform; late DependencyManager dependencyManager; - final keys = HostedUiKeys(hostedUiConfig.appClientId); + final keys = HostedUiKeys(mockConfig.auth!.userPoolClientId!); AWSLogger().logLevel = LogLevel.verbose; @@ -35,7 +35,7 @@ void main() { server = MockOAuthServer(); secureStorage = MockSecureStorage(); dependencyManager = DependencyManager() - ..addInstance(hostedUiConfig) + ..addInstance(mockConfig.auth!) ..addInstance(secureStorage) ..addInstance(server.httpClient) ..addInstance>(const MockDispatcher()); @@ -69,7 +69,8 @@ void main() { test('missing state throws', () async { final parameters = await server.authorize( await platform.getSignInUri( - redirectUri: Uri.parse(hostedUiConfig.signInRedirectUri), + redirectUri: + Uri.parse(mockConfig.auth!.oauth!.redirectSignInUri.first), ), ); @@ -86,7 +87,8 @@ void main() { test('mismatched state throws', () async { final parameters = await server.authorize( await platform.getSignInUri( - redirectUri: Uri.parse(hostedUiConfig.signInRedirectUri), + redirectUri: + Uri.parse(mockConfig.auth!.oauth!.redirectSignInUri.first), ), ); @@ -105,7 +107,8 @@ void main() { test('succeeds', () async { final parameters = await server.authorize( await platform.getSignInUri( - redirectUri: Uri.parse(hostedUiConfig.signInRedirectUri), + redirectUri: + Uri.parse(mockConfig.auth!.oauth!.redirectSignInUri.first), ), ); diff --git a/packages/auth/amplify_auth_cognito_test/test/plugin/auth_providers_test.dart b/packages/auth/amplify_auth_cognito_test/test/plugin/auth_providers_test.dart index 9f3dd8aa3f..5d75ff5223 100644 --- a/packages/auth/amplify_auth_cognito_test/test/plugin/auth_providers_test.dart +++ b/packages/auth/amplify_auth_cognito_test/test/plugin/auth_providers_test.dart @@ -66,8 +66,9 @@ void main() { seedStorage( secureStorage, - userPoolKeys: CognitoUserPoolKeys(userPoolConfig.appClientId), - identityPoolKeys: CognitoIdentityPoolKeys(identityPoolConfig.poolId), + userPoolKeys: CognitoUserPoolKeys(mockConfig.auth!.userPoolClientId!), + identityPoolKeys: + CognitoIdentityPoolKeys(mockConfig.auth!.identityPoolId!), ); await plugin.addPlugin(authProviderRepo: testAuthRepo); diff --git a/packages/auth/amplify_auth_cognito_test/test/plugin/forget_device_test.dart b/packages/auth/amplify_auth_cognito_test/test/plugin/forget_device_test.dart index 97e9c1bf98..d3e983c42c 100644 --- a/packages/auth/amplify_auth_cognito_test/test/plugin/forget_device_test.dart +++ b/packages/auth/amplify_auth_cognito_test/test/plugin/forget_device_test.dart @@ -15,8 +15,9 @@ import 'package:test/test.dart'; void main() { AmplifyLogger().logLevel = LogLevel.verbose; - final userPoolKeys = CognitoUserPoolKeys(userPoolConfig.appClientId); - final identityPoolKeys = CognitoIdentityPoolKeys(identityPoolConfig.poolId); + final userPoolKeys = CognitoUserPoolKeys(mockConfig.auth!.userPoolClientId!); + final identityPoolKeys = + CognitoIdentityPoolKeys(mockConfig.auth!.identityPoolId!); final testAuthRepo = AmplifyAuthProviderRepository(); late DeviceMetadataRepository repo; @@ -31,7 +32,8 @@ void main() { secureStorage, userPoolKeys: userPoolKeys, identityPoolKeys: identityPoolKeys, - deviceKeys: CognitoDeviceKeys(userPoolConfig.appClientId, username), + deviceKeys: + CognitoDeviceKeys(mockConfig.auth!.userPoolClientId!, username), ); plugin = AmplifyAuthCognitoDart( secureStorageFactory: (_) => secureStorage, diff --git a/packages/auth/amplify_auth_cognito_test/test/plugin/remember_device_test.dart b/packages/auth/amplify_auth_cognito_test/test/plugin/remember_device_test.dart index c548ff58fd..21e546402e 100644 --- a/packages/auth/amplify_auth_cognito_test/test/plugin/remember_device_test.dart +++ b/packages/auth/amplify_auth_cognito_test/test/plugin/remember_device_test.dart @@ -17,8 +17,9 @@ enum DeviceState { untracked, tracked, remembered } void main() { AmplifyLogger().logLevel = LogLevel.verbose; - final userPoolKeys = CognitoUserPoolKeys(userPoolConfig.appClientId); - final identityPoolKeys = CognitoIdentityPoolKeys(identityPoolConfig.poolId); + final userPoolKeys = CognitoUserPoolKeys(mockConfig.auth!.userPoolClientId!); + final identityPoolKeys = + CognitoIdentityPoolKeys(mockConfig.auth!.identityPoolId!); final testAuthRepo = AmplifyAuthProviderRepository(); final mockUpdateDeviceStatusResponse = UpdateDeviceStatusResponse(); @@ -44,7 +45,8 @@ void main() { secureStorage, userPoolKeys: userPoolKeys, identityPoolKeys: identityPoolKeys, - deviceKeys: CognitoDeviceKeys(userPoolConfig.appClientId, username), + deviceKeys: + CognitoDeviceKeys(mockConfig.auth!.userPoolClientId!, username), ); plugin = AmplifyAuthCognitoDart( secureStorageFactory: (_) => secureStorage, diff --git a/packages/auth/amplify_auth_cognito_test/test/plugin/sign_out_test.dart b/packages/auth/amplify_auth_cognito_test/test/plugin/sign_out_test.dart index d687e2c34b..878d8af180 100644 --- a/packages/auth/amplify_auth_cognito_test/test/plugin/sign_out_test.dart +++ b/packages/auth/amplify_auth_cognito_test/test/plugin/sign_out_test.dart @@ -23,9 +23,10 @@ final throwsSignedOutException = throwsA(isA()); // Follows signOut test cases: // https://github.com/aws-amplify/amplify-android/tree/main/aws-auth-cognito/src/test/resources/feature-test/testsuites/signOut void main() { - final userPoolKeys = CognitoUserPoolKeys(userPoolConfig.appClientId); - final identityPoolKeys = CognitoIdentityPoolKeys(identityPoolConfig.poolId); - final hostedUiKeys = HostedUiKeys(hostedUiConfig.appClientId); + final userPoolKeys = CognitoUserPoolKeys(mockConfig.auth!.userPoolClientId!); + final identityPoolKeys = + CognitoIdentityPoolKeys(mockConfig.auth!.identityPoolId!); + final hostedUiKeys = HostedUiKeys(mockConfig.auth!.userPoolClientId!); late AmplifyAuthCognitoDart plugin; late CognitoAuthStateMachine stateMachine; diff --git a/packages/auth/amplify_auth_cognito_test/test/state/hosted_ui_state_machine_test.dart b/packages/auth/amplify_auth_cognito_test/test/state/hosted_ui_state_machine_test.dart index 1dfa3acc48..61f51eb2bc 100644 --- a/packages/auth/amplify_auth_cognito_test/test/state/hosted_ui_state_machine_test.dart +++ b/packages/auth/amplify_auth_cognito_test/test/state/hosted_ui_state_machine_test.dart @@ -37,10 +37,12 @@ class MockHostedUiPlatform extends HostedUiPlatform { }) async {} @override - Uri get signInRedirectUri => config.signInRedirectUris.first; + Uri get signInRedirectUri => + Uri.parse(authOutputs.oauth!.redirectSignInUri.first); @override - Uri get signOutRedirectUri => config.signOutRedirectUris.first; + Uri get signOutRedirectUri => + Uri.parse(authOutputs.oauth!.redirectSignOutUri.first); } class FailingHostedUiPlatform extends HostedUiPlatform { @@ -62,15 +64,17 @@ class FailingHostedUiPlatform extends HostedUiPlatform { } @override - Uri get signInRedirectUri => config.signInRedirectUris.first; + Uri get signInRedirectUri => + Uri.parse(authOutputs.oauth!.redirectSignInUri.first); @override - Uri get signOutRedirectUri => config.signOutRedirectUris.first; + Uri get signOutRedirectUri => + Uri.parse(authOutputs.oauth!.redirectSignOutUri.first); } void main() { AWSLogger().logLevel = LogLevel.verbose; - final keys = HostedUiKeys(hostedUiConfig.appClientId); + final keys = HostedUiKeys(mockConfig.auth!.userPoolClientId!); group('HostedUiStateMachine', () { late MockOAuthServer server; @@ -93,7 +97,7 @@ void main() { ..addInstance>( const MockDispatcher(), ) - ..addInstance(hostedUiConfig); + ..addInstance(mockConfig.auth!); final platform = stateMachine.create(); final authorizationUri = await platform.getSignInUri(); @@ -109,13 +113,13 @@ void main() { expect(authorizationUri.queryParameters['scope'], isNotNull); expect( authorizationUri.queryParameters['scope'], - hostedUiConfig.scopes.join(' '), + mockConfig.auth!.oauth!.scopes.join(' '), ); expect(authorizationUri.queryParameters['response_type'], 'code'); expect( authorizationUri.queryParameters['client_id'], - hostedUiConfig.appClientId, + mockConfig.auth!.userPoolClientId, ); expect(authorizationUri.queryParameters['code_challenge'], isNotNull);