Skip to content

Commit 7040bb7

Browse files
committed
update code
1 parent 4b9350d commit 7040bb7

File tree

6 files changed

+36
-46
lines changed

6 files changed

+36
-46
lines changed

AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/CredentialStore/MigrateLegacyCredentialStore.swift

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,6 @@ struct MigrateLegacyCredentialStore: Action {
312312
authProvider: nil,
313313
idpIdentifier: nil
314314
)
315-
#if os(iOS) || os(macOS) || os(visionOS)
316315
return .hostedUI(.init(
317316
scopes: scopes ?? [],
318317
providerInfo: provider,
@@ -324,18 +323,6 @@ struct MigrateLegacyCredentialStore: Action {
324323
prompt: nil,
325324
resource: nil
326325
))
327-
#else
328-
return .hostedUI(.init(
329-
scopes: scopes ?? [],
330-
providerInfo: provider,
331-
presentationAnchor: nil,
332-
preferPrivateSession: false,
333-
nonce: nil,
334-
language: nil,
335-
loginHint: nil,
336-
resource: nil
337-
))
338-
#endif
339326
default:
340327
return .apiBased(.userSRP)
341328
}

AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Operations/Helpers/HostedUISignInHelper.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ struct HostedUISignInHelper: DefaultLogger {
135135
nonce: pluginOptions?.nonce,
136136
language: pluginOptions?.language,
137137
loginHint: pluginOptions?.loginHint,
138-
prompt: pluginOptions?.prompt,
138+
promptValues: pluginOptions?.prompt,
139139
resource: pluginOptions?.resource
140140
)
141141
let signInData = SignInEventData(

AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/StateMachine/CodeGen/Data/HostedUIOptions.swift

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,8 @@ struct HostedUIOptions {
2424

2525
let loginHint: String?
2626

27-
#if os(iOS) || os(macOS) || os(visionOS)
28-
let prompt: [AWSAuthWebUISignInOptions.Prompt]?
29-
#endif
27+
let prompt: String?
28+
3029
let resource: String?
3130
}
3231

@@ -60,9 +59,7 @@ extension HostedUIOptions: Codable {
6059
self.nonce = try values.decode(String.self, forKey: .nonce)
6160
self.language = try values.decode(String.self, forKey: .language)
6261
self.loginHint = try values.decode(String.self, forKey: .loginHint)
63-
#if os(iOS) || os(macOS) || os(visionOS)
64-
self.prompt = try values.decode(Array.self, forKey: .prompt)
65-
#endif
62+
self.prompt = try values.decode(String.self, forKey: .prompt)
6663
self.resource = try values.decode(String.self, forKey: .resource)
6764
}
6865

@@ -74,11 +71,37 @@ extension HostedUIOptions: Codable {
7471
try container.encode(nonce, forKey: .nonce)
7572
try container.encode(language, forKey: .language)
7673
try container.encode(loginHint, forKey: .loginHint)
77-
#if os(iOS) || os(macOS) || os(visionOS)
7874
try container.encodeIfPresent(prompt, forKey: .prompt)
79-
#endif
8075
try container.encode(resource, forKey: .resource)
8176
}
8277
}
8378

8479
extension HostedUIOptions: Equatable { }
80+
81+
#if os(iOS) || os(macOS) || os(visionOS)
82+
extension HostedUIOptions {
83+
init(
84+
scopes: [String],
85+
providerInfo: HostedUIProviderInfo,
86+
presentationAnchor: AuthUIPresentationAnchor?,
87+
preferPrivateSession: Bool,
88+
nonce: String?,
89+
language: String?,
90+
loginHint: String?,
91+
promptValues: [AWSAuthWebUISignInOptions.Prompt]?,
92+
resource: String?
93+
) {
94+
self.init(
95+
scopes: scopes,
96+
providerInfo: providerInfo,
97+
presentationAnchor: presentationAnchor,
98+
preferPrivateSession: preferPrivateSession,
99+
nonce: nonce,
100+
language: language,
101+
loginHint: loginHint,
102+
prompt: promptValues?.map { "\($0.rawValue)" }.joined(separator: " "),
103+
resource: resource
104+
)
105+
}
106+
}
107+
#endif

AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Support/HostedUI/HostedUIRequestHelper.swift

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,9 @@ enum HostedUIRequestHelper {
6767
if let loginHint = options.loginHint {
6868
components.queryItems?.append(.init(name: "login_hint", value: loginHint))
6969
}
70-
#if os(iOS) || os(macOS) || os(visionOS)
7170
if let prompt = options.prompt {
72-
let promptValue = prompt.map { "\($0.rawValue)" }.joined(separator: " ")
73-
components.queryItems?.append(.init(name: "prompt", value: promptValue))
71+
components.queryItems?.append(.init(name: "prompt", value: prompt))
7472
}
75-
#endif
7673
if let resource = options.resource {
7774
components.queryItems?.append(.init(name: "resource", value: resource))
7875
}

AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/Mocks/MockData/SignedInData+Mock.swift

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ extension SignedInData {
3030

3131
static var hostedUISignInData: SignedInData {
3232
let tokens = AWSCognitoUserPoolTokens.testData
33-
#if os(iOS) || os(macOS) || os(visionOS)
3433
return SignedInData(
3534
signedInDate: Date(),
3635
signInMethod: .hostedUI(.init(
@@ -46,21 +45,5 @@ extension SignedInData {
4645
)),
4746
cognitoUserPoolTokens: tokens
4847
)
49-
#else
50-
return SignedInData(
51-
signedInDate: Date(),
52-
signInMethod: .hostedUI(.init(
53-
scopes: [],
54-
providerInfo: .init(authProvider: .google, idpIdentifier: ""),
55-
presentationAnchor: nil,
56-
preferPrivateSession: false,
57-
nonce: nil,
58-
language: nil,
59-
loginHint: nil,
60-
resource: nil
61-
)),
62-
cognitoUserPoolTokens: tokens
63-
)
64-
#endif
6548
}
6649
}

AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/Support/HostedUIRequestHelperTests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import Amplify
1111
import XCTest
1212
@testable import AWSCognitoAuthPlugin
1313

14-
#if os(iOS) || os(macOS) || os(visionOS)
1514
class HostedUIRequestHelperTests: XCTestCase {
1615
private var configuration: HostedUIConfigurationData!
1716
private let result = HostedUIResult(
@@ -90,6 +89,7 @@ class HostedUIRequestHelperTests: XCTestCase {
9089
XCTAssertEqual("Basic \(encodedSecret)", header)
9190
}
9291

92+
#if os(iOS) || os(macOS) || os(visionOS)
9393
/// Given: A HostedUI configuration that defines a client secret
9494
/// When: HostedUIRequestHelper.createSignInURL is invoked with cognito oidc parameters
9595
/// Then: A URL is generated that contains all the cognito oidc parameters in url query parameters
@@ -108,7 +108,7 @@ class HostedUIRequestHelperTests: XCTestCase {
108108
nonce: "nonce",
109109
language: "en",
110110
loginHint: "username",
111-
prompt: [.login, .consent],
111+
promptValues: [.login, .consent],
112112
resource: "http://localhost"
113113
)
114114
)
@@ -124,5 +124,5 @@ class HostedUIRequestHelperTests: XCTestCase {
124124
XCTAssertEqual("login consent", urlComponents.queryItems?.first(where: { $0.name == "prompt"})?.value)
125125
XCTAssertEqual("http://localhost", urlComponents.queryItems?.first(where: { $0.name == "resource"})?.value)
126126
}
127+
#endif
127128
}
128-
#endif

0 commit comments

Comments
 (0)