Skip to content

Commit

Permalink
fix(auth): gen2 config oauth domain (#3663)
Browse files Browse the repository at this point in the history
  • Loading branch information
lawmicha authored May 1, 2024
1 parent 0009ab3 commit 8ff89a8
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 34 deletions.
3 changes: 1 addition & 2 deletions Amplify/Core/Configuration/AmplifyOutputsData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ public struct AmplifyOutputsData: Codable {
@_spi(InternalAmplifyConfiguration)
public struct OAuth: Codable {
public let identityProviders: [String]
public let cognitoDomain: String
public let customDomain: String?
public let domain: String
public let scopes: [String]
public let redirectSignInUri: [String]
public let redirectSignOutUri: [String]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ struct ConfigurationHelper {

return createHostedConfiguration(appClientId: configuration.userPoolClientId,
clientSecret: nil,
domain: oauth.customDomain ?? oauth.cognitoDomain,
domain: oauth.domain,
scopes: oauth.scopes,
signInRedirectURI: signInRedirectURI,
signOutRedirectURI: signOutRedirectURI)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ final class ConfigurationHelperTests: XCTestCase {
userPoolId: "poolId",
userPoolClientId: "clientId",
oauth: AmplifyOutputsData.Auth.OAuth(identityProviders: ["provider1", "provider2"],
cognitoDomain: "cognitoDomain",
customDomain: nil,
domain: "domain",
scopes: ["scope1", "scope2"],
redirectSignInUri: ["redirect1", "redirect2"],
redirectSignOutUri: ["signOut1", "signOut2"],
Expand All @@ -62,35 +61,7 @@ final class ConfigurationHelperTests: XCTestCase {
XCTAssertEqual(hostedUIConfig.clientId, "clientId")
XCTAssertNil(hostedUIConfig.clientSecret, "Client secret should be nil as its not supported in Gen2")
XCTAssertEqual(hostedUIConfig.oauth.scopes, ["scope1", "scope2"])
XCTAssertEqual(hostedUIConfig.oauth.domain, "cognitoDomain")
XCTAssertEqual(hostedUIConfig.oauth.signInRedirectURI, "redirect1")
XCTAssertEqual(hostedUIConfig.oauth.signOutRedirectURI, "signOut1")
}

/// Test Oauth section's `customDomain` overwrites `cognitoDomain`
func testParseUserPoolData_WithOAuth_CustomDomain() throws {
let config = AmplifyOutputsData.Auth(
awsRegion: "us-east-1",
userPoolId: "poolId",
userPoolClientId: "clientId",
oauth: AmplifyOutputsData.Auth.OAuth(identityProviders: ["provider1", "provider2"],
cognitoDomain: "cognitoDomain",
customDomain: "customDomain",
scopes: ["scope1", "scope2"],
redirectSignInUri: ["redirect1", "redirect2"],
redirectSignOutUri: ["signOut1", "signOut2"],
responseType: "responseType"))

guard let config = ConfigurationHelper.parseUserPoolData(config),
let hostedUIConfig = config.hostedUIConfig else {
XCTFail("Expected to parse UserPoolData into object")
return
}

XCTAssertEqual(hostedUIConfig.clientId, "clientId")
XCTAssertNil(hostedUIConfig.clientSecret)
XCTAssertEqual(hostedUIConfig.oauth.scopes, ["scope1", "scope2"])
XCTAssertEqual(hostedUIConfig.oauth.domain, "customDomain")
XCTAssertEqual(hostedUIConfig.oauth.domain, "domain")
XCTAssertEqual(hostedUIConfig.oauth.signInRedirectURI, "redirect1")
XCTAssertEqual(hostedUIConfig.oauth.signOutRedirectURI, "signOut1")
}
Expand Down

0 comments on commit 8ff89a8

Please sign in to comment.