Skip to content

Commit

Permalink
Update to schema change to add cognito and custom domains
Browse files Browse the repository at this point in the history
  • Loading branch information
mattcreaser committed Apr 15, 2024
1 parent 222986a commit e9e6044
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ interface AmplifyOutputsData {
@InternalAmplifyApi
interface Oauth {
val identityProviders: List<IdentityProviders>
val domain: String
val cognitoDomain: String
val customDomain: String?
val scopes: List<String>
val redirectSignInUri: List<String>
val redirectSignOutUri: List<String>
Expand Down Expand Up @@ -278,7 +279,8 @@ internal data class AmplifyOutputsDataImpl(
@Serializable
data class Oauth(
override val identityProviders: List<IdentityProviders>,
override val domain: String,
override val cognitoDomain: String,
override val customDomain: String?,
override val scopes: List<String>,
override val redirectSignInUri: List<String>,
override val redirectSignOutUri: List<String>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ class PasswordPolicyBuilder : AmplifyOutputsData.Auth.PasswordPolicy {

class OauthBuilder : AmplifyOutputsData.Auth.Oauth {
override val identityProviders: MutableList<AmplifyOutputsData.Auth.Oauth.IdentityProviders> = mutableListOf()
override var domain: String = "domain"
override var cognitoDomain: String = "domain"
override var customDomain: String? = null
override val scopes: MutableList<String> = mutableListOf()
override val redirectSignInUri: MutableList<String> = mutableListOf()
override val redirectSignOutUri: MutableList<String> = mutableListOf()
Expand Down

0 comments on commit e9e6044

Please sign in to comment.