diff --git a/aws-auth-cognito/src/main/java/com/amplifyframework/auth/cognito/AuthConfiguration.kt b/aws-auth-cognito/src/main/java/com/amplifyframework/auth/cognito/AuthConfiguration.kt index 0a18e2663..ebb6037f2 100644 --- a/aws-auth-cognito/src/main/java/com/amplifyframework/auth/cognito/AuthConfiguration.kt +++ b/aws-auth-cognito/src/main/java/com/amplifyframework/auth/cognito/AuthConfiguration.kt @@ -122,7 +122,8 @@ data class AuthConfiguration internal constructor( OauthConfiguration( appClient = auth.userPoolClientId, appSecret = null, // Not supported in Gen2 - domain = it.domain, + // Use the custom domain if specified, otherwise use the generated cognito domain + domain = it.customDomain ?: it.cognitoDomain, scopes = it.scopes.toSet(), // Note: Gen2 config gives an array for these values, while Gen1 is just a String. In Gen1 // if you specify multiple URIs the CLI will join them to a comma-delimited string in the json. diff --git a/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/AuthConfigurationTest.kt b/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/AuthConfigurationTest.kt index 23844763a..41c717474 100644 --- a/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/AuthConfigurationTest.kt +++ b/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/AuthConfigurationTest.kt @@ -44,7 +44,7 @@ class AuthConfigurationTest { requireSymbols = true } oauth { - domain = "https://test.com" + cognitoDomain = "https://test.com" identityProviders += AmplifyOutputsData.Auth.Oauth.IdentityProviders.GOOGLE scopes += listOf("myScope", "myScope2") redirectSignInUri += "https://test.com/signin" @@ -119,6 +119,22 @@ class AuthConfigurationTest { configuration.identityPool.shouldBeNull() } + @Test + fun `uses custom oauth domain if specified`() { + val data = amplifyOutputsData { + auth { + oauth { + cognitoDomain = "cognito" + customDomain = "custom" + } + } + } + + val configuration = AuthConfiguration.from(data) + + configuration.oauth?.domain shouldBe "custom" + } + @Test fun `throws exception if auth is not configured in amplify outputs`() { val data = amplifyOutputsData { diff --git a/core/src/main/java/com/amplifyframework/core/configuration/AmplifyOutputsData.kt b/core/src/main/java/com/amplifyframework/core/configuration/AmplifyOutputsData.kt index 84e916aea..36d3b496d 100644 --- a/core/src/main/java/com/amplifyframework/core/configuration/AmplifyOutputsData.kt +++ b/core/src/main/java/com/amplifyframework/core/configuration/AmplifyOutputsData.kt @@ -86,7 +86,8 @@ interface AmplifyOutputsData { @InternalAmplifyApi interface Oauth { val identityProviders: List - val domain: String + val cognitoDomain: String + val customDomain: String? val scopes: List val redirectSignInUri: List val redirectSignOutUri: List @@ -278,7 +279,8 @@ internal data class AmplifyOutputsDataImpl( @Serializable data class Oauth( override val identityProviders: List, - override val domain: String, + override val cognitoDomain: String, + override val customDomain: String?, override val scopes: List, override val redirectSignInUri: List, override val redirectSignOutUri: List, diff --git a/testutils/src/main/java/com/amplifyframework/testutils/configuration/AmplifyOutputsDataBuilder.kt b/testutils/src/main/java/com/amplifyframework/testutils/configuration/AmplifyOutputsDataBuilder.kt index 29adcad63..8500824e1 100644 --- a/testutils/src/main/java/com/amplifyframework/testutils/configuration/AmplifyOutputsDataBuilder.kt +++ b/testutils/src/main/java/com/amplifyframework/testutils/configuration/AmplifyOutputsDataBuilder.kt @@ -93,7 +93,8 @@ class PasswordPolicyBuilder : AmplifyOutputsData.Auth.PasswordPolicy { class OauthBuilder : AmplifyOutputsData.Auth.Oauth { override val identityProviders: MutableList = mutableListOf() - override var domain: String = "domain" + override var cognitoDomain: String = "domain" + override var customDomain: String? = null override val scopes: MutableList = mutableListOf() override val redirectSignInUri: MutableList = mutableListOf() override val redirectSignOutUri: MutableList = mutableListOf()