Skip to content

Commit 27342fe

Browse files
authored
refactor(Auth): Changed the Auth plugins user agent to use Amplify (#577)
1 parent 0e359d6 commit 27342fe

File tree

16 files changed

+267
-218
lines changed

16 files changed

+267
-218
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.1'
1111
$AMPLIFY_RELEASE_TAG = "v#{$AMPLIFY_VERSION}"
1212

13-
$AWS_SDK_VERSION = '2.13.4'
13+
$AWS_SDK_VERSION = '2.13.5'
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.1'
33
$AMPLIFY_RELEASE_TAG = "v#{$AMPLIFY_VERSION}"
44

5-
$AWS_SDK_VERSION = '2.13.4'
5+
$AWS_SDK_VERSION = '2.13.5'
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.1'
1111
$AMPLIFY_RELEASE_TAG = "v#{$AMPLIFY_VERSION}"
1212

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

1616
Pod::Spec.new do |s|

AmplifyPlugins/API/Podfile.lock

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,47 +3,47 @@ PODS:
33
- Amplify/Default (= 1.0.1)
44
- Amplify/Default (1.0.1)
55
- AmplifyPlugins/AWSCognitoAuthPlugin (1.0.1):
6-
- AWSAuthCore (~> 2.13.4)
7-
- AWSCore (~> 2.13.4)
8-
- AWSMobileClient (~> 2.13.4)
6+
- AWSAuthCore (~> 2.13.5)
7+
- AWSCore (~> 2.13.5)
8+
- AWSMobileClient (~> 2.13.5)
99
- AWSPluginsCore (= 1.0.1)
1010
- AmplifyTestCommon (1.0.1):
1111
- Amplify (= 1.0.1)
1212
- AmplifyTestCommon/AWSPluginsTestCommon (= 1.0.1)
1313
- AmplifyTestCommon/AWSPluginsTestCommon (1.0.1):
1414
- Amplify (= 1.0.1)
15-
- AWSCore (~> 2.13.4)
15+
- AWSCore (~> 2.13.5)
1616
- AWSPluginsCore (= 1.0.1)
1717
- AppSyncRealTimeClient (1.1.6):
1818
- Starscream (= 3.0.6)
19-
- AWSAuthCore (2.13.4):
20-
- AWSCore (= 2.13.4)
21-
- AWSCognitoIdentityProvider (2.13.4):
19+
- AWSAuthCore (2.13.5):
20+
- AWSCore (= 2.13.5)
21+
- AWSCognitoIdentityProvider (2.13.5):
2222
- AWSCognitoIdentityProviderASF (= 1.0.1)
23-
- AWSCore (= 2.13.4)
23+
- AWSCore (= 2.13.5)
2424
- AWSCognitoIdentityProviderASF (1.0.1)
25-
- AWSCore (2.13.4)
26-
- AWSMobileClient (2.13.4):
27-
- AWSAuthCore (= 2.13.4)
28-
- AWSCognitoIdentityProvider (= 2.13.4)
25+
- AWSCore (2.13.5)
26+
- AWSMobileClient (2.13.5):
27+
- AWSAuthCore (= 2.13.5)
28+
- AWSCognitoIdentityProvider (= 2.13.5)
2929
- AWSPluginsCore (1.0.1):
3030
- Amplify (= 1.0.1)
31-
- AWSCore (~> 2.13.4)
32-
- AWSMobileClient (~> 2.13.4)
31+
- AWSCore (~> 2.13.5)
32+
- AWSMobileClient (~> 2.13.5)
3333
- CwlCatchException (1.0.2)
3434
- CwlPreconditionTesting (1.1.1):
3535
- CwlCatchException
3636
- ReachabilitySwift (5.0.0)
3737
- Starscream (3.0.6)
38-
- SwiftFormat/CLI (0.44.13)
38+
- SwiftFormat/CLI (0.44.14)
3939
- SwiftLint (0.39.2)
4040

4141
DEPENDENCIES:
4242
- Amplify (from `../../`)
4343
- AmplifyPlugins/AWSCognitoAuthPlugin (from `../../`)
4444
- AmplifyTestCommon (from `../../`)
4545
- AppSyncRealTimeClient (~> 1.1.0)
46-
- AWSMobileClient (~> 2.13.4)
46+
- AWSMobileClient (~> 2.13.5)
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`)
@@ -52,7 +52,7 @@ DEPENDENCIES:
5252
- SwiftLint
5353

5454
SPEC REPOS:
55-
https://cdn.cocoapods.org/:
55+
trunk:
5656
- AppSyncRealTimeClient
5757
- AWSAuthCore
5858
- AWSCognitoIdentityProvider
@@ -90,22 +90,22 @@ CHECKOUT OPTIONS:
9090

9191
SPEC CHECKSUMS:
9292
Amplify: 58bd74cef8478c40e93df97db8d6e97db645f849
93-
AmplifyPlugins: 7847bd4bbe97743443f5d9fabd026b1c097cbb2e
94-
AmplifyTestCommon: 81f2cb494229ebbc0cadbe7c7044e7484182b727
93+
AmplifyPlugins: 579447713c30bc6a10e33238b6943ed97243bde9
94+
AmplifyTestCommon: 1c794366e80adf3cf0c17487cebee863b16500d6
9595
AppSyncRealTimeClient: 4a2ccdc1722750a1f4d76e216f9bfb1cf12f10de
96-
AWSAuthCore: 72b4bd064c28985ea5345c62759632d511de342a
97-
AWSCognitoIdentityProvider: a2d1d2857316519c018c03ac8205cf78154db5c0
96+
AWSAuthCore: 135ff7620051fd35d1d6a0da23c0613598cbc6a3
97+
AWSCognitoIdentityProvider: 94290a6f8603e05542b4f8ef3d92dae85ff86706
9898
AWSCognitoIdentityProviderASF: f94f1a502e72ef3d0a1de93e10bf7a79c8698118
99-
AWSCore: 06beea22b6bdbfe9f5ab5015c6901e8475c746a8
100-
AWSMobileClient: 33ecce524fbc011d543dae8306ca29a43ecb72e5
101-
AWSPluginsCore: b6fb2dc62e35a24261544709826e142c0c082c6f
99+
AWSCore: 5122783f63f0f6467f61289461ced7324b2e94d1
100+
AWSMobileClient: aa7b304dfa5c79c4bcc2cb879b476da16ef4294a
101+
AWSPluginsCore: f3be008c119cffa60b86d32ffed905759f071289
102102
CwlCatchException: 70a52ae44ea5d46db7bd385f801a94942420cd8c
103103
CwlPreconditionTesting: d33a4e4f285c0b885fddcae5dfedfbb34d4f3961
104104
ReachabilitySwift: 985039c6f7b23a1da463388634119492ff86c825
105105
Starscream: ef3ece99d765eeccb67de105bfa143f929026cf5
106-
SwiftFormat: 87e745cb2f6509894a44ac4f311a8722a9ebcb8b
106+
SwiftFormat: a5ab293a7f6a812bec6f4ffc5507b7ed08f7f6e1
107107
SwiftLint: 22ccbbe3b8008684be5955693bab135e0ed6a447
108108

109-
PODFILE CHECKSUM: c5ca54ced4ba8835a7d63fc7d12880ae4532cb16
109+
PODFILE CHECKSUM: 36210dbb4ee100c2203d947149c3f0c7628db7a3
110110

111111
COCOAPODS: 1.9.3

AmplifyPlugins/Analytics/Podfile.lock

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,52 +3,52 @@ PODS:
33
- Amplify/Default (= 1.0.1)
44
- Amplify/Default (1.0.1)
55
- AmplifyPlugins/AWSCognitoAuthPlugin (1.0.1):
6-
- AWSAuthCore (~> 2.13.4)
7-
- AWSCore (~> 2.13.4)
8-
- AWSMobileClient (~> 2.13.4)
6+
- AWSAuthCore (~> 2.13.5)
7+
- AWSCore (~> 2.13.5)
8+
- AWSMobileClient (~> 2.13.5)
99
- AWSPluginsCore (= 1.0.1)
1010
- AmplifyTestCommon (1.0.1):
1111
- Amplify (= 1.0.1)
1212
- AmplifyTestCommon/AWSPluginsTestCommon (= 1.0.1)
1313
- AmplifyTestCommon/AWSPluginsTestCommon (1.0.1):
1414
- Amplify (= 1.0.1)
15-
- AWSCore (~> 2.13.4)
15+
- AWSCore (~> 2.13.5)
1616
- AWSPluginsCore (= 1.0.1)
17-
- AWSAuthCore (2.13.4):
18-
- AWSCore (= 2.13.4)
19-
- AWSCognitoIdentityProvider (2.13.4):
17+
- AWSAuthCore (2.13.5):
18+
- AWSCore (= 2.13.5)
19+
- AWSCognitoIdentityProvider (2.13.5):
2020
- AWSCognitoIdentityProviderASF (= 1.0.1)
21-
- AWSCore (= 2.13.4)
21+
- AWSCore (= 2.13.5)
2222
- AWSCognitoIdentityProviderASF (1.0.1)
23-
- AWSCore (2.13.4)
24-
- AWSMobileClient (2.13.4):
25-
- AWSAuthCore (= 2.13.4)
26-
- AWSCognitoIdentityProvider (= 2.13.4)
27-
- AWSPinpoint (2.13.4):
28-
- AWSCore (= 2.13.4)
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)
2929
- AWSPluginsCore (1.0.1):
3030
- Amplify (= 1.0.1)
31-
- AWSCore (~> 2.13.4)
32-
- AWSMobileClient (~> 2.13.4)
31+
- AWSCore (~> 2.13.5)
32+
- AWSMobileClient (~> 2.13.5)
3333
- CwlCatchException (1.0.2)
3434
- CwlPreconditionTesting (1.1.1):
3535
- CwlCatchException
36-
- SwiftFormat/CLI (0.44.13)
36+
- SwiftFormat/CLI (0.44.14)
3737
- SwiftLint (0.39.2)
3838

3939
DEPENDENCIES:
4040
- Amplify (from `../../`)
4141
- AmplifyPlugins/AWSCognitoAuthPlugin (from `../../`)
4242
- AmplifyTestCommon (from `../../`)
43-
- AWSPinpoint (~> 2.13.4)
43+
- AWSPinpoint (~> 2.13.5)
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`)
4747
- SwiftFormat/CLI
4848
- SwiftLint
4949

5050
SPEC REPOS:
51-
https://cdn.cocoapods.org/:
51+
trunk:
5252
- AWSAuthCore
5353
- AWSCognitoIdentityProvider
5454
- AWSCognitoIdentityProviderASF
@@ -84,20 +84,20 @@ CHECKOUT OPTIONS:
8484

8585
SPEC CHECKSUMS:
8686
Amplify: 58bd74cef8478c40e93df97db8d6e97db645f849
87-
AmplifyPlugins: 7847bd4bbe97743443f5d9fabd026b1c097cbb2e
88-
AmplifyTestCommon: 81f2cb494229ebbc0cadbe7c7044e7484182b727
89-
AWSAuthCore: 72b4bd064c28985ea5345c62759632d511de342a
90-
AWSCognitoIdentityProvider: a2d1d2857316519c018c03ac8205cf78154db5c0
87+
AmplifyPlugins: 579447713c30bc6a10e33238b6943ed97243bde9
88+
AmplifyTestCommon: 1c794366e80adf3cf0c17487cebee863b16500d6
89+
AWSAuthCore: 135ff7620051fd35d1d6a0da23c0613598cbc6a3
90+
AWSCognitoIdentityProvider: 94290a6f8603e05542b4f8ef3d92dae85ff86706
9191
AWSCognitoIdentityProviderASF: f94f1a502e72ef3d0a1de93e10bf7a79c8698118
92-
AWSCore: 06beea22b6bdbfe9f5ab5015c6901e8475c746a8
93-
AWSMobileClient: 33ecce524fbc011d543dae8306ca29a43ecb72e5
94-
AWSPinpoint: 82468e86fc58a5f0b9d9c115d705f034fb142286
95-
AWSPluginsCore: b6fb2dc62e35a24261544709826e142c0c082c6f
92+
AWSCore: 5122783f63f0f6467f61289461ced7324b2e94d1
93+
AWSMobileClient: aa7b304dfa5c79c4bcc2cb879b476da16ef4294a
94+
AWSPinpoint: 888db6d4a27969f03f20384723252db5466d54a3
95+
AWSPluginsCore: f3be008c119cffa60b86d32ffed905759f071289
9696
CwlCatchException: 70a52ae44ea5d46db7bd385f801a94942420cd8c
9797
CwlPreconditionTesting: d33a4e4f285c0b885fddcae5dfedfbb34d4f3961
98-
SwiftFormat: 87e745cb2f6509894a44ac4f311a8722a9ebcb8b
98+
SwiftFormat: a5ab293a7f6a812bec6f4ffc5507b7ed08f7f6e1
9999
SwiftLint: 22ccbbe3b8008684be5955693bab135e0ed6a447
100100

101-
PODFILE CHECKSUM: 09968374faafb5dd9aff6885771b78408733a96d
101+
PODFILE CHECKSUM: 48d1574dddce5cef7bdb7b05b06fc588ee22956e
102102

103103
COCOAPODS: 1.9.3

AmplifyPlugins/Auth/AWSCognitoAuthPlugin/AWSCognitoAuthPlugin+Configure.swift

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import Foundation
99
import Amplify
1010
import AWSPluginsCore
1111
import AWSMobileClient
12+
import AWSCore
1213

1314
extension AWSCognitoAuthPlugin {
1415

@@ -30,7 +31,12 @@ extension AWSCognitoAuthPlugin {
3031
let authConfig = (try? JSONSerialization.jsonObject(with: configurationData, options: [])
3132
as? [String: Any]) ?? [:]
3233
AWSInfo.configureDefaultAWSInfo(authConfig)
33-
let awsMobileClient = AWSMobileClientAdapter()
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)
3440
try awsMobileClient.initialize()
3541
let authenticationProvider = AuthenticationProviderAdapter(awsMobileClient: awsMobileClient)
3642
let authorizationProvider = AuthorizationProviderAdapter(awsMobileClient: awsMobileClient)
@@ -44,6 +50,7 @@ extension AWSCognitoAuthPlugin {
4450
hubEventHandler: hubEventHandler)
4551
} catch let authError as AuthError {
4652
throw authError
53+
4754
} catch {
4855
let amplifyError = AuthError.configuration(
4956
"Error configuring \(String(describing: self))",
@@ -55,6 +62,39 @@ extension AWSCognitoAuthPlugin {
5562
}
5663
}
5764

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(
69+
"Error configuring \(String(describing: self))",
70+
"""
71+
Could not read Cognito identity pool information from the configuration. Make sure that auth category
72+
is properly configured and auth information are present in the configuration. You can use Amplify CLI to
73+
configure the auth category.
74+
""")
75+
throw amplifyError
76+
}
77+
let region = (regionString as NSString).aws_regionTypeValue()
78+
let anonymousCredentialProvider = AWSAnonymousCredentialsProvider()
79+
return AmplifyAWSServiceConfiguration(region: region, credentialsProvider: anonymousCredentialProvider)
80+
}
81+
82+
func userPoolServiceConfiguration(from authConfiguration: JSONValue) throws -> AmplifyAWSServiceConfiguration {
83+
let regionKeyPath = "CognitoUserPool.Default.Region"
84+
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
93+
}
94+
let region = (regionString as NSString).aws_regionTypeValue()
95+
return AmplifyAWSServiceConfiguration(region: region)
96+
}
97+
5898
// MARK: Internal
5999

60100
/// Internal configure method to set the properties of the plugin

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,17 @@
77

88
import Amplify
99
import AWSMobileClient
10+
import AWSPluginsCore
1011

1112
class AWSMobileClientAdapter: AWSMobileClientBehavior {
1213

1314
let awsMobileClient: AWSMobileClient
1415

15-
init() {
16+
init(userPoolConfiguration: AmplifyAWSServiceConfiguration,
17+
identityPoolConfiguration: AmplifyAWSServiceConfiguration) {
18+
19+
AWSMobileClient.updateCognitoService(userPoolConfiguration: userPoolConfiguration,
20+
identityPoolConfiguration: identityPoolConfiguration)
1621
self.awsMobileClient = AWSMobileClient.default()
1722
}
1823

0 commit comments

Comments
 (0)