aws-sdk-android
aws-sdk-android copied to clipboard
CognitoUserPool should read Endpoint from awsconfiguration.json
CognitoUserPool doesn't read the value of the custom endpoint set in awsconfiguration.json file
Constructor with the problem
public CognitoUserPool(Context context, AWSConfiguration awsConfiguration)
This behavior is implemented in AWSMobileClient here
A fix will essentially read the Endpoint set in the file and call client.setEndpoint(cognitoUserPoolCustomEndpoint) instead of setting the region after checking if it is set in the file
I can open a PR for the fix, I wanted to check if this behavior is done intentionally or not
How did you set the custom endpoint in awsconfiguration.json file? Manully change the file or using Amplify CLI?
How did you set the custom endpoint in
awsconfiguration.jsonfile? Manully change the file or using Amplify CLI?
By manually changing it or it can also be built by a JSON object it looks like this in the file
"CognitoUserPool": {
"Default": {
"PoolId": "us-west-2_",
"AppClientId": "123",
"Region": "us-west-2",
"Endpoint": "https://example.com/"
}
}
You can also see it being parsed in AWSMobileClient here
The issue here is for the repo aws-android-sdk-cognitoidentityprovider CognitoUserPool.java class
For reference: PR in amplify-ios to fix this issue https://github.com/aws-amplify/amplify-ios/pull/1715
@mohamed-khaled-hsn My understanding is this is already present in Android SDK as per this PR and comment and description in the iOS fix PR. Is my understanding correct? or are you looking for any additional feature?
@mohamed-khaled-hsn My understanding is this is already present in Android SDK as per this PR and comment and description in the iOS fix PR. Is my understanding correct? or are you looking for any additional feature?
I'm looking for additional feature
would like to use the CognitoUserPool constructor that takes an AWSConfiguration but I can't because I'm using a custom endpoint and currently it doesn't parse it
I had written a workaround here that uses the constructor mentioned in the PR you linked
/**
* Builds a [CognitoUserPool] from the passed this [AWSConfiguration],
* this doesn't use the constructor that takes [AWSConfiguration] because it doesn't parse
* custom cognito endpoint, see issue https://github.com/aws-amplify/aws-sdk-android/issues/2747
*/
fun AWSConfiguration.cognitoUserPool(context: Context): CognitoUserPool {
val cognitoUserPoolJson = optJsonObject("CognitoUserPool")
val poolId = cognitoUserPoolJson.getString("PoolId")
val clientId = cognitoUserPoolJson.getString("AppClientId")
val clientSecret = cognitoUserPoolJson.optString("AppClientSecret")
val pinpointEndpointId = CognitoPinpointSharedContext.getPinpointEndpoint(
context,
cognitoUserPoolJson.optString("PinpointAppId")
)
val cognitoUserPoolCustomEndpoint = cognitoUserPoolJson.optString("Endpoint")
val client = AmazonCognitoIdentityProviderClient(
AnonymousAWSCredentials(),
ClientConfiguration()
).apply {
if (cognitoUserPoolCustomEndpoint.isNotEmpty()) {
endpoint = cognitoUserPoolCustomEndpoint
} else {
setRegion(Region.getRegion(Regions.fromName(cognitoUserPoolJson.getString("Region"))))
}
}
return CognitoUserPool(
context,
poolId,
clientId,
clientSecret,
client,
pinpointEndpointId,
cognitoUserPoolCustomEndpoint
)
}
Hope that cleared the confusion