Skip to content

Commit 6f58a4e

Browse files
authored
fix(auth): Fix issue in auth configure where it fails if both Cognito services are not present (#589)
Auth plugin now require at least one of the Cognito Service configuration to properly configure. Added unit test for different scenarios of configuration.
1 parent 2708869 commit 6f58a4e

File tree

16 files changed

+344
-197
lines changed

16 files changed

+344
-197
lines changed

AWSPluginsCore.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
$AMPLIFY_VERSION = '1.0.2'
1111
$AMPLIFY_RELEASE_TAG = "v#{$AMPLIFY_VERSION}"
1212

13-
$AWS_SDK_VERSION = '2.13.5'
13+
$AWS_SDK_VERSION = '2.13.6'
1414
$OPTIMISTIC_AWS_SDK_VERSION = "~> #{$AWS_SDK_VERSION}"
1515

1616
Pod::Spec.new do |s|

AWSPredictionsPlugin.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
$AMPLIFY_VERSION = '1.0.2'
33
$AMPLIFY_RELEASE_TAG = "v#{$AMPLIFY_VERSION}"
44

5-
$AWS_SDK_VERSION = '2.13.5'
5+
$AWS_SDK_VERSION = '2.13.6'
66
$OPTIMISTIC_AWS_SDK_VERSION = "~> #{$AWS_SDK_VERSION}"
77

88
Pod::Spec.new do |s|

AmplifyPlugins.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
$AMPLIFY_VERSION = '1.0.2'
1111
$AMPLIFY_RELEASE_TAG = "v#{$AMPLIFY_VERSION}"
1212

13-
$AWS_SDK_VERSION = '2.13.5'
13+
$AWS_SDK_VERSION = '2.13.6'
1414
$OPTIMISTIC_AWS_SDK_VERSION = "~> #{$AWS_SDK_VERSION}"
1515

1616
Pod::Spec.new do |s|

AmplifyPlugins/API/Podfile.lock

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,33 @@ PODS:
33
- Amplify/Default (= 1.0.2)
44
- Amplify/Default (1.0.2)
55
- AmplifyPlugins/AWSCognitoAuthPlugin (1.0.2):
6-
- AWSAuthCore (~> 2.13.5)
7-
- AWSCore (~> 2.13.5)
8-
- AWSMobileClient (~> 2.13.5)
6+
- AWSAuthCore (~> 2.13.6)
7+
- AWSCore (~> 2.13.6)
8+
- AWSMobileClient (~> 2.13.6)
99
- AWSPluginsCore (= 1.0.2)
1010
- AmplifyTestCommon (1.0.2):
1111
- Amplify (= 1.0.2)
1212
- AmplifyTestCommon/AWSPluginsTestCommon (= 1.0.2)
1313
- AmplifyTestCommon/AWSPluginsTestCommon (1.0.2):
1414
- Amplify (= 1.0.2)
15-
- AWSCore (~> 2.13.5)
15+
- AWSCore (~> 2.13.6)
1616
- AWSPluginsCore (= 1.0.2)
1717
- AppSyncRealTimeClient (1.1.6):
1818
- Starscream (= 3.0.6)
19-
- AWSAuthCore (2.13.5):
20-
- AWSCore (= 2.13.5)
21-
- AWSCognitoIdentityProvider (2.13.5):
19+
- AWSAuthCore (2.13.6):
20+
- AWSCore (= 2.13.6)
21+
- AWSCognitoIdentityProvider (2.13.6):
2222
- AWSCognitoIdentityProviderASF (= 1.0.1)
23-
- AWSCore (= 2.13.5)
23+
- AWSCore (= 2.13.6)
2424
- AWSCognitoIdentityProviderASF (1.0.1)
25-
- AWSCore (2.13.5)
26-
- AWSMobileClient (2.13.5):
27-
- AWSAuthCore (= 2.13.5)
28-
- AWSCognitoIdentityProvider (= 2.13.5)
25+
- AWSCore (2.13.6)
26+
- AWSMobileClient (2.13.6):
27+
- AWSAuthCore (= 2.13.6)
28+
- AWSCognitoIdentityProvider (= 2.13.6)
2929
- AWSPluginsCore (1.0.2):
3030
- Amplify (= 1.0.2)
31-
- AWSCore (~> 2.13.5)
32-
- AWSMobileClient (~> 2.13.5)
31+
- AWSCore (~> 2.13.6)
32+
- AWSMobileClient (~> 2.13.6)
3333
- CwlCatchException (1.0.2)
3434
- CwlPreconditionTesting (1.1.1):
3535
- CwlCatchException
@@ -43,7 +43,7 @@ DEPENDENCIES:
4343
- AmplifyPlugins/AWSCognitoAuthPlugin (from `../../`)
4444
- AmplifyTestCommon (from `../../`)
4545
- AppSyncRealTimeClient (~> 1.1.0)
46-
- AWSMobileClient (~> 2.13.5)
46+
- AWSMobileClient (~> 2.13.6)
4747
- AWSPluginsCore (from `../../`)
4848
- CwlCatchException (from `https://github.com/mattgallagher/CwlCatchException.git`, tag `1.2.0`)
4949
- CwlPreconditionTesting (from `https://github.com/mattgallagher/CwlPreconditionTesting.git`, tag `1.2.0`)
@@ -90,15 +90,15 @@ CHECKOUT OPTIONS:
9090

9191
SPEC CHECKSUMS:
9292
Amplify: b4deddc12754b7e6c31dc6f321e1ff5d70aa6cf5
93-
AmplifyPlugins: c8cf007b601647169e54ed985e83082b2243498a
94-
AmplifyTestCommon: 743929a3a7d00dd2303d65aac59a0f2b43b5913d
93+
AmplifyPlugins: 14f4defa031e224de90fafc971a38c19c34fb6e3
94+
AmplifyTestCommon: 5be7bf7cfd515a8ea0dc66eb3d9e6900288d3306
9595
AppSyncRealTimeClient: 4a2ccdc1722750a1f4d76e216f9bfb1cf12f10de
96-
AWSAuthCore: 135ff7620051fd35d1d6a0da23c0613598cbc6a3
97-
AWSCognitoIdentityProvider: 94290a6f8603e05542b4f8ef3d92dae85ff86706
96+
AWSAuthCore: 62e92b5ffbd66b8ba0eac471e7f90ccfa76cf63b
97+
AWSCognitoIdentityProvider: 05f14f7c892df9ff764268d2ac33b4e95288e603
9898
AWSCognitoIdentityProviderASF: f94f1a502e72ef3d0a1de93e10bf7a79c8698118
99-
AWSCore: 5122783f63f0f6467f61289461ced7324b2e94d1
100-
AWSMobileClient: aa7b304dfa5c79c4bcc2cb879b476da16ef4294a
101-
AWSPluginsCore: fb2cc6aaff8a7ef49c2a53620f1a0e9c61dafcb4
99+
AWSCore: 2b6015f278770e745b4863ac5f45e007e647f298
100+
AWSMobileClient: 420a899c4691c7f0991daa35daee82a84396ec63
101+
AWSPluginsCore: 3e6d6be84232b1c114935134a2b6763c0ad06b5e
102102
CwlCatchException: 70a52ae44ea5d46db7bd385f801a94942420cd8c
103103
CwlPreconditionTesting: d33a4e4f285c0b885fddcae5dfedfbb34d4f3961
104104
ReachabilitySwift: 985039c6f7b23a1da463388634119492ff86c825

AmplifyPlugins/Analytics/Podfile.lock

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,33 @@ PODS:
33
- Amplify/Default (= 1.0.2)
44
- Amplify/Default (1.0.2)
55
- AmplifyPlugins/AWSCognitoAuthPlugin (1.0.2):
6-
- AWSAuthCore (~> 2.13.5)
7-
- AWSCore (~> 2.13.5)
8-
- AWSMobileClient (~> 2.13.5)
6+
- AWSAuthCore (~> 2.13.6)
7+
- AWSCore (~> 2.13.6)
8+
- AWSMobileClient (~> 2.13.6)
99
- AWSPluginsCore (= 1.0.2)
1010
- AmplifyTestCommon (1.0.2):
1111
- Amplify (= 1.0.2)
1212
- AmplifyTestCommon/AWSPluginsTestCommon (= 1.0.2)
1313
- AmplifyTestCommon/AWSPluginsTestCommon (1.0.2):
1414
- Amplify (= 1.0.2)
15-
- AWSCore (~> 2.13.5)
15+
- AWSCore (~> 2.13.6)
1616
- AWSPluginsCore (= 1.0.2)
17-
- AWSAuthCore (2.13.5):
18-
- AWSCore (= 2.13.5)
19-
- AWSCognitoIdentityProvider (2.13.5):
17+
- AWSAuthCore (2.13.6):
18+
- AWSCore (= 2.13.6)
19+
- AWSCognitoIdentityProvider (2.13.6):
2020
- AWSCognitoIdentityProviderASF (= 1.0.1)
21-
- AWSCore (= 2.13.5)
21+
- AWSCore (= 2.13.6)
2222
- AWSCognitoIdentityProviderASF (1.0.1)
23-
- AWSCore (2.13.5)
24-
- AWSMobileClient (2.13.5):
25-
- AWSAuthCore (= 2.13.5)
26-
- AWSCognitoIdentityProvider (= 2.13.5)
27-
- AWSPinpoint (2.13.5):
28-
- AWSCore (= 2.13.5)
23+
- AWSCore (2.13.6)
24+
- AWSMobileClient (2.13.6):
25+
- AWSAuthCore (= 2.13.6)
26+
- AWSCognitoIdentityProvider (= 2.13.6)
27+
- AWSPinpoint (2.13.6):
28+
- AWSCore (= 2.13.6)
2929
- AWSPluginsCore (1.0.2):
3030
- Amplify (= 1.0.2)
31-
- AWSCore (~> 2.13.5)
32-
- AWSMobileClient (~> 2.13.5)
31+
- AWSCore (~> 2.13.6)
32+
- AWSMobileClient (~> 2.13.6)
3333
- CwlCatchException (1.0.2)
3434
- CwlPreconditionTesting (1.1.1):
3535
- CwlCatchException
@@ -40,7 +40,7 @@ DEPENDENCIES:
4040
- Amplify (from `../../`)
4141
- AmplifyPlugins/AWSCognitoAuthPlugin (from `../../`)
4242
- AmplifyTestCommon (from `../../`)
43-
- AWSPinpoint (~> 2.13.5)
43+
- AWSPinpoint (~> 2.13.6)
4444
- AWSPluginsCore (from `../../`)
4545
- CwlCatchException (from `https://github.com/mattgallagher/CwlCatchException.git`, tag `1.2.0`)
4646
- CwlPreconditionTesting (from `https://github.com/mattgallagher/CwlPreconditionTesting.git`, tag `1.2.0`)
@@ -84,15 +84,15 @@ CHECKOUT OPTIONS:
8484

8585
SPEC CHECKSUMS:
8686
Amplify: b4deddc12754b7e6c31dc6f321e1ff5d70aa6cf5
87-
AmplifyPlugins: c8cf007b601647169e54ed985e83082b2243498a
88-
AmplifyTestCommon: 743929a3a7d00dd2303d65aac59a0f2b43b5913d
89-
AWSAuthCore: 135ff7620051fd35d1d6a0da23c0613598cbc6a3
90-
AWSCognitoIdentityProvider: 94290a6f8603e05542b4f8ef3d92dae85ff86706
87+
AmplifyPlugins: 14f4defa031e224de90fafc971a38c19c34fb6e3
88+
AmplifyTestCommon: 5be7bf7cfd515a8ea0dc66eb3d9e6900288d3306
89+
AWSAuthCore: 62e92b5ffbd66b8ba0eac471e7f90ccfa76cf63b
90+
AWSCognitoIdentityProvider: 05f14f7c892df9ff764268d2ac33b4e95288e603
9191
AWSCognitoIdentityProviderASF: f94f1a502e72ef3d0a1de93e10bf7a79c8698118
92-
AWSCore: 5122783f63f0f6467f61289461ced7324b2e94d1
93-
AWSMobileClient: aa7b304dfa5c79c4bcc2cb879b476da16ef4294a
94-
AWSPinpoint: 888db6d4a27969f03f20384723252db5466d54a3
95-
AWSPluginsCore: fb2cc6aaff8a7ef49c2a53620f1a0e9c61dafcb4
92+
AWSCore: 2b6015f278770e745b4863ac5f45e007e647f298
93+
AWSMobileClient: 420a899c4691c7f0991daa35daee82a84396ec63
94+
AWSPinpoint: 91cc98431e9d46c7e7f53987e180e4f2a9728177
95+
AWSPluginsCore: 3e6d6be84232b1c114935134a2b6763c0ad06b5e
9696
CwlCatchException: 70a52ae44ea5d46db7bd385f801a94942420cd8c
9797
CwlPreconditionTesting: d33a4e4f285c0b885fddcae5dfedfbb34d4f3961
9898
SwiftFormat: a5ab293a7f6a812bec6f4ffc5507b7ed08f7f6e1

AmplifyPlugins/Auth/AWSCognitoAuthPlugin/AWSCognitoAuthPlugin+Configure.swift

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,7 @@ extension AWSCognitoAuthPlugin {
3131
let authConfig = (try? JSONSerialization.jsonObject(with: configurationData, options: [])
3232
as? [String: Any]) ?? [:]
3333
AWSInfo.configureDefaultAWSInfo(authConfig)
34-
35-
let identityPoolConfig = try identityPoolServiceConfiguration(from: jsonValueConfiguration)
36-
let userPoolConfig = try userPoolServiceConfiguration(from: jsonValueConfiguration)
37-
38-
let awsMobileClient = AWSMobileClientAdapter(userPoolConfiguration: userPoolConfig,
39-
identityPoolConfiguration: identityPoolConfig)
34+
let awsMobileClient = try awsMobileClientAdapter(from: jsonValueConfiguration)
4035
try awsMobileClient.initialize()
4136
let authenticationProvider = AuthenticationProviderAdapter(awsMobileClient: awsMobileClient)
4237
let authorizationProvider = AuthorizationProviderAdapter(awsMobileClient: awsMobileClient)
@@ -62,34 +57,42 @@ extension AWSCognitoAuthPlugin {
6257
}
6358
}
6459

65-
func identityPoolServiceConfiguration(from authConfiguration: JSONValue) throws -> AmplifyAWSServiceConfiguration {
66-
let regionKeyPath = "CredentialsProvider.CognitoIdentity.Default.Region"
67-
guard case .string(let regionString) = authConfiguration.value(at: regionKeyPath) else {
68-
let amplifyError = AuthError.configuration(
60+
func awsMobileClientAdapter(from authConfiguration: JSONValue) throws -> AWSMobileClientBehavior {
61+
let identityPoolConfig = identityPoolServiceConfiguration(from: authConfiguration)
62+
let userPoolConfig = userPoolServiceConfiguration(from: authConfiguration)
63+
64+
// Auth plugin require atleast one of the Cognito service to work. Throw an error if both the service
65+
// configuration are nil.
66+
guard identityPoolConfig != nil || userPoolConfig != nil else {
67+
throw AuthError.configuration(
6968
"Error configuring \(String(describing: self))",
7069
"""
71-
Could not read Cognito identity pool information from the configuration. Make sure that auth category
70+
Could not read Cognito Service configuration from the auth configuration. Make sure that auth category
7271
is properly configured and auth information are present in the configuration. You can use Amplify CLI to
7372
configure the auth category.
7473
""")
75-
throw amplifyError
74+
75+
}
76+
return AWSMobileClientAdapter(userPoolConfiguration: userPoolConfig,
77+
identityPoolConfiguration: identityPoolConfig)
78+
}
79+
80+
func identityPoolServiceConfiguration(from authConfiguration: JSONValue) -> AmplifyAWSServiceConfiguration? {
81+
let regionKeyPath = "CredentialsProvider.CognitoIdentity.Default.Region"
82+
guard case .string(let regionString) = authConfiguration.value(at: regionKeyPath) else {
83+
Amplify.Logging.warn("Could not read Cognito identity pool information from the configuration.")
84+
return nil
7685
}
7786
let region = (regionString as NSString).aws_regionTypeValue()
7887
let anonymousCredentialProvider = AWSAnonymousCredentialsProvider()
7988
return AmplifyAWSServiceConfiguration(region: region, credentialsProvider: anonymousCredentialProvider)
8089
}
8190

82-
func userPoolServiceConfiguration(from authConfiguration: JSONValue) throws -> AmplifyAWSServiceConfiguration {
91+
func userPoolServiceConfiguration(from authConfiguration: JSONValue) -> AmplifyAWSServiceConfiguration? {
8392
let regionKeyPath = "CognitoUserPool.Default.Region"
8493
guard case .string(let regionString) = authConfiguration.value(at: regionKeyPath) else {
85-
let amplifyError = AuthError.configuration(
86-
"Error configuring \(String(describing: self))",
87-
"""
88-
Could not read Cognito user pool information from the configuration. Make sure that auth category is
89-
properly configured and auth information are present in the configuration. You can use Amplify CLI to
90-
configure the auth category.
91-
""")
92-
throw amplifyError
94+
Amplify.Logging.warn("Could not read Cognito user pool information from the configuration.")
95+
return nil
9396
}
9497
let region = (regionString as NSString).aws_regionTypeValue()
9598
return AmplifyAWSServiceConfiguration(region: region)

AmplifyPlugins/Auth/AWSCognitoAuthPlugin/Service/AWSMobileClient/AWSMobileClientAdapter.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ class AWSMobileClientAdapter: AWSMobileClientBehavior {
1313

1414
let awsMobileClient: AWSMobileClient
1515

16-
init(userPoolConfiguration: AmplifyAWSServiceConfiguration,
17-
identityPoolConfiguration: AmplifyAWSServiceConfiguration) {
16+
init(userPoolConfiguration: AmplifyAWSServiceConfiguration?,
17+
identityPoolConfiguration: AmplifyAWSServiceConfiguration?) {
1818

1919
AWSMobileClient.updateCognitoService(userPoolConfiguration: userPoolConfiguration,
2020
identityPoolConfiguration: identityPoolConfiguration)

0 commit comments

Comments
 (0)