Skip to content

Commit

Permalink
chore!: remove deprecated auth types
Browse files Browse the repository at this point in the history
  • Loading branch information
Jordan-Nelson committed Apr 23, 2024
1 parent 5d080ce commit e975914
Show file tree
Hide file tree
Showing 56 changed files with 69 additions and 1,369 deletions.
15 changes: 0 additions & 15 deletions packages/amplify_core/lib/src/category/amplify_auth_category.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1292,21 +1292,6 @@ class AuthCategory extends AmplifyCategory<AuthPluginInterface> {
),
);

/// {@macro amplify_core.amplify_auth_category.send_attribute_verification_code}
@Deprecated('Use sendUserAttributeVerificationCode.')
Future<ResendUserAttributeConfirmationCodeResult>
resendUserAttributeConfirmationCode({
required AuthUserAttributeKey userAttributeKey,
ResendUserAttributeConfirmationCodeOptions? options,
}) =>
identifyCall(
AuthCategoryMethod.sendUserAttributeVerificationCode,
() => defaultPlugin.sendUserAttributeVerificationCode(
userAttributeKey: userAttributeKey,
options: options,
),
);

/// {@template amplify_core.amplify_auth_category.set_up_totp}
/// Initiates setup of a time-based one-time passcode (TOTP) MFA method for the
/// current user.
Expand Down
2 changes: 0 additions & 2 deletions packages/amplify_core/lib/src/config/auth/auth_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ class AuthConfig extends AmplifyPluginConfigMap {
CognitoUserPoolConfig? userPoolConfig,
CognitoIdentityPoolConfig? identityPoolConfig,
CognitoOAuthConfig? hostedUiConfig,
AuthenticationFlowType? authenticationFlowType,
List<SocialProvider>? socialProviders,
List<CognitoUserAttributeKey>? usernameAttributes,
List<CognitoUserAttributeKey>? signupAttributes,
Expand All @@ -40,7 +39,6 @@ class AuthConfig extends AmplifyPluginConfigMap {
auth: AWSConfigMap.withDefault(
CognitoAuthConfig(
oAuth: hostedUiConfig,
authenticationFlowType: authenticationFlowType,
socialProviders: socialProviders,
usernameAttributes: usernameAttributes ?? const [],
signupAttributes: signupAttributes ?? const [],
Expand Down
9 changes: 0 additions & 9 deletions packages/amplify_core/lib/src/config/auth/cognito/auth.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ part 'auth.g.dart';
class CognitoAuthConfig with AWSEquatable<CognitoAuthConfig>, AWSSerializable {
const CognitoAuthConfig({
this.oAuth,
this.authenticationFlowType,
this.socialProviders,
this.usernameAttributes,
this.signupAttributes,
Expand All @@ -29,10 +28,6 @@ class CognitoAuthConfig with AWSEquatable<CognitoAuthConfig>, AWSSerializable {
@JsonKey(name: 'OAuth')
final CognitoOAuthConfig? oAuth;

@JsonKey(
unknownEnumValue: JsonKey.nullForUndefinedEnumValue,
)
final AuthenticationFlowType? authenticationFlowType;
final List<SocialProvider>? socialProviders;
final List<CognitoUserAttributeKey>? usernameAttributes;
final List<CognitoUserAttributeKey>? signupAttributes;
Expand All @@ -44,7 +39,6 @@ class CognitoAuthConfig with AWSEquatable<CognitoAuthConfig>, AWSSerializable {
@override
List<Object?> get props => [
oAuth,
authenticationFlowType,
socialProviders,
usernameAttributes,
signupAttributes,
Expand All @@ -56,7 +50,6 @@ class CognitoAuthConfig with AWSEquatable<CognitoAuthConfig>, AWSSerializable {

CognitoAuthConfig copyWith({
CognitoOAuthConfig? oAuth,
AuthenticationFlowType? authenticationFlowType,
List<SocialProvider>? socialProviders,
List<CognitoUserAttributeKey>? usernameAttributes,
List<CognitoUserAttributeKey>? signupAttributes,
Expand All @@ -67,8 +60,6 @@ class CognitoAuthConfig with AWSEquatable<CognitoAuthConfig>, AWSSerializable {
}) {
return CognitoAuthConfig(
oAuth: oAuth ?? this.oAuth,
authenticationFlowType:
authenticationFlowType ?? this.authenticationFlowType,
socialProviders: socialProviders ??
(this.socialProviders == null
? null
Expand Down
13 changes: 0 additions & 13 deletions packages/amplify_core/lib/src/config/auth/cognito/auth.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@ enum AuthenticationFlowType {
@JsonValue('USER_PASSWORD_AUTH')
userPasswordAuth('USER_PASSWORD_AUTH'),

/// Authentication flow for custom flow which are backed by Lambda triggers.
@Deprecated('Use customAuthWithSrp or customAuthWithoutSrp instead')
@JsonValue('CUSTOM_AUTH')
customAuth('CUSTOM_AUTH'),

/// Authentication flow which start with SRP and then move to custom auth
/// flow.
@JsonValue('CUSTOM_AUTH_WITH_SRP')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,18 +153,6 @@ abstract class AuthPluginInterface extends AmplifyPluginInterface {
);
}

/// {@macro amplify_core.amplify_auth_category.send_attribute_verification_code}
@Deprecated('Use sendUserAttributeVerificationCode instead.')
Future<ResendUserAttributeConfirmationCodeResult>
resendUserAttributeConfirmationCode({
required AuthUserAttributeKey userAttributeKey,
ResendUserAttributeConfirmationCodeOptions? options,
}) {
throw UnimplementedError(
'resendUserAttributeConfirmationCode() has not been implemented.',
);
}

/// {@macro amplify_core.amplify_auth_category.send_attribute_verification_code}
Future<SendUserAttributeVerificationCodeResult>
sendUserAttributeVerificationCode({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,3 @@ abstract class SendUserAttributeVerificationCodePluginOptions
/// {@macro amplify_core.auth.send_user_attribute_verification_code_plugin_options}
const SendUserAttributeVerificationCodePluginOptions();
}

/// {@macro amplify_core.send_attribute_verification_code_options}
@Deprecated('Use SendUserAttributeVerificationCodeOptions.')
typedef ResendUserAttributeConfirmationCodeOptions
= SendUserAttributeVerificationCodeOptions;

/// @nodoc
/// {@macro amplify_core.auth.send_user_attribute_verification_code_plugin_options}
@Deprecated('Use SendUserAttributeVerificationCodePluginOptions.')
typedef ResendUserAttributeConfirmationCodePluginOptions
= SendUserAttributeVerificationCodePluginOptions;
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,3 @@ class SendUserAttributeVerificationCodeResult
Map<String, Object?> toJson() =>
_$SendUserAttributeVerificationCodeResultToJson(this);
}

/// {@macro amplify_core.send_user_attribute_verification_code_result}
@Deprecated('Use SendUserAttributeVerificationCodeResult.')
typedef ResendUserAttributeConfirmationCodeResult
= SendUserAttributeVerificationCodeResult;
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,6 @@ class AuthCodeDeliveryDetails
/// being updated.
final AuthUserAttributeKey? attributeKey;

/// If a user attribute update is underway, this is the name of the attribute
/// being updated.
@Deprecated('Use attributeKey instead')
String? get attributeName => attributeKey?.key;

@override
List<Object?> get props => [attributeKey, deliveryMedium, destination];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@

import 'package:amplify_core/amplify_core.dart';

/// @nodoc
/// {@macro amplify_core.auth.fetch_auth_session_options}
@Deprecated('Use FetchAuthSessionOptions instead')
typedef AuthSessionOptions = FetchAuthSessionOptions;

/// {@category Auth}
/// {@template amplify_core.auth.fetch_auth_session_options}
/// Options for `Amplify.Auth.fetchAuthSession`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@
// SPDX-License-Identifier: Apache-2.0
import 'package:amplify_core/amplify_core.dart';

/// @nodoc
/// {@macro amplify_core.auth.get_current_user_options}
@Deprecated('Use GetCurrentUserOptions instead')
typedef AuthUserOptions = GetCurrentUserOptions;

/// {@category Auth}
/// {@template amplify_core.auth.get_current_user_options}
/// Options for `Amplify.Auth.getCurrentUser`.
Expand Down
9 changes: 2 additions & 7 deletions packages/amplify_core/test/config/auth_config_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import 'package:path/path.dart' as path;
import 'package:test/test.dart';

import 'testdata/test_values.dart';
import 'utils/remove_deprecated_key.dart';

void main() {
group('Config', () {
Expand All @@ -24,6 +25,7 @@ void main() {
test(name, () {
final json = File(file.path).readAsStringSync();
final configJson = jsonDecode(json) as Map<String, Object?>;
removeDeprecatedKeys(configJson);
final config = AmplifyConfig.fromJson(configJson);
final expectedConfig = expected[name]!;
final cognitoConfig = config.auth!.awsPlugin!.auth!.default$!;
Expand Down Expand Up @@ -53,7 +55,6 @@ void main() {

const expected = <String, CognitoAuthConfig>{
'auth_with_all_attributes': CognitoAuthConfig(
authenticationFlowType: AuthenticationFlowType.userSrpAuth,
signupAttributes: [
CognitoUserAttributeKey.address,
CognitoUserAttributeKey.birthdate,
Expand Down Expand Up @@ -87,7 +88,6 @@ const expected = <String, CognitoAuthConfig>{
usernameAttributes: [],
),
'auth_with_email': CognitoAuthConfig(
authenticationFlowType: AuthenticationFlowType.userSrpAuth,
signupAttributes: [
CognitoUserAttributeKey.email,
],
Expand All @@ -113,7 +113,6 @@ const expected = <String, CognitoAuthConfig>{
],
),
'auth_with_multi_alias': CognitoAuthConfig(
authenticationFlowType: AuthenticationFlowType.userSrpAuth,
signupAttributes: [
CognitoUserAttributeKey.email,
CognitoUserAttributeKey.phoneNumber,
Expand All @@ -132,7 +131,6 @@ const expected = <String, CognitoAuthConfig>{
],
),
'auth_with_username_no_attributes': CognitoAuthConfig(
authenticationFlowType: AuthenticationFlowType.userSrpAuth,
signupAttributes: [
CognitoUserAttributeKey.email,
],
Expand All @@ -150,7 +148,6 @@ const expected = <String, CognitoAuthConfig>{
usernameAttributes: [],
),
'auth_with_email_or_phone': CognitoAuthConfig(
authenticationFlowType: AuthenticationFlowType.userSrpAuth,
socialProviders: [],
usernameAttributes: [
CognitoUserAttributeKey.email,
Expand Down Expand Up @@ -185,7 +182,6 @@ const expected = <String, CognitoAuthConfig>{
signOutRedirectUri: OAUTH_SIGNOUT,
webDomain: OAUTH_DOMAIN,
),
authenticationFlowType: AuthenticationFlowType.userSrpAuth,
socialProviders: [
SocialProvider.facebook,
SocialProvider.google,
Expand Down Expand Up @@ -215,7 +211,6 @@ const expected = <String, CognitoAuthConfig>{
],
),
'auth_with_username': CognitoAuthConfig(
authenticationFlowType: AuthenticationFlowType.userSrpAuth,
socialProviders: [],
usernameAttributes: [],
signupAttributes: [
Expand Down
8 changes: 3 additions & 5 deletions packages/amplify_core/test/config/cli_config_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'package:test/test.dart';

import 'testdata/cli_generated.dart';
import 'testdata/test_values.dart';
import 'utils/remove_deprecated_key.dart';

void main() {
group('Config', () {
Expand All @@ -17,6 +18,7 @@ void main() {
final name = testData.name;
test(name, () {
final json = jsonDecode(testData.config) as Map<String, Object?>;
removeDeprecatedKeys(json);
final parsed = AmplifyConfig.fromJson(json.cast());
final expectedConfig = expected[name]!;
expect(parsed, equals(expectedConfig));
Expand Down Expand Up @@ -95,12 +97,8 @@ const expected = {
signOutRedirectUri: OAUTH_SIGNOUT,
webDomain: OAUTH_DOMAIN,
),
authenticationFlowType: AuthenticationFlowType.userSrpAuth,
),
'DefaultCustomAuth': CognitoAuthConfig(
// ignore: deprecated_member_use_from_same_package
authenticationFlowType: AuthenticationFlowType.customAuth,
),
'DefaultCustomAuth': CognitoAuthConfig(),
}),
cognitoUserPool: AWSConfigMap({
'CustomEndpoint': CognitoUserPoolConfig(
Expand Down
62 changes: 62 additions & 0 deletions packages/amplify_core/test/config/utils/remove_deprecated_key.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

/// Removes keys that are no longer supported in the config as of Amplify
/// Flutter version 2.
///
/// The tests in this directory test against real configs generated by the Gen1
/// CLI and assert that serializing a json object to an AmplifyConfig and back
/// to JSON does not change the shape. Deprecated keys will not be present in
/// the output and need to be removed before comparison.
void removeDeprecatedKeys(Map<String, Object?> object) {
removeKey(
object,
[
'auth',
'plugins',
'awsCognitoAuthPlugin',
'Auth',
'DefaultCustomAuth',
'authenticationFlowType',
],
);
removeKey(
object,
[
'auth',
'plugins',
'awsCognitoAuthPlugin',
'Auth',
'Default',
'authenticationFlowType',
],
);
}

/// Removes a deeply nested key from a map if it exists in the map.
///
/// [path] is the path to the deeply nested key.
///
/// Example
/// ```
/// final obj = {
/// 'foo': {
/// 'bar': {
/// 'baz':'val'
/// }
/// }
/// }
/// print(obj); // => {'foo': {'bar': {'baz': 'val'}}}
/// removeKey(obj, ['foo', 'bar', 'baz']);
/// print(obj); // => {'foo': {'bar': {}}}
///
/// ```
void removeKey(Map<String, Object?> object, List<String> path) {
if (path.isEmpty) return;
if (path.length == 1) {
object.removeWhere((key, value) => key == path.first);
} else if (object.containsKey(path.first) &&
object[path.first] is Map<String, Object?>) {
removeKey(object[path.first] as Map<String, Object?>, path.sublist(1));
}
}
Loading

0 comments on commit e975914

Please sign in to comment.