Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SDKS-546 TextInputCallback Support #261

Merged
merged 3 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions FRAuth/FRAuth.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
objects = {

/* Begin PBXBuildFile section */
1B6037E62B505924009090DF /* TextInputCallback.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1B6037E52B505924009090DF /* TextInputCallback.swift */; };
1B85DA132B85208C0023E953 /* TextInputCallbackTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1B85DA122B85208C0023E953 /* TextInputCallbackTests.swift */; };
3A1B43D0284510B700EAFC9D /* AtomicDictionary.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A1B43CF284510B700EAFC9D /* AtomicDictionary.swift */; };
3A1B43D3284524B900EAFC9D /* AtomicDictionaryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A1B43D2284524B900EAFC9D /* AtomicDictionaryTests.swift */; };
3A3E785B2AAF6BE8007962B7 /* FRAppIntegrityCallback.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A3E785A2AAF6BE8007962B7 /* FRAppIntegrityCallback.swift */; };
Expand All @@ -19,10 +21,11 @@
3A53E4DA2A153AF200E17DDF /* PolicyAdviceCreatorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A53E4D92A153AF200E17DDF /* PolicyAdviceCreatorTests.swift */; };
3A67B8832AD83946003331C5 /* FRAppIntegrityKeys.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A67B8822AD83946003331C5 /* FRAppIntegrityKeys.swift */; };
3A6D26672A1345400099D877 /* PolicyAdviceCreator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A6D26662A1345400099D877 /* PolicyAdviceCreator.swift */; };
3AB062FA2AE6224D00C4B47C /* FRAppIntegrityKeysTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AB062F92AE6224D00C4B47C /* FRAppIntegrityKeysTests.swift */; };
9536C56C2B865DD600B2DFDD /* AA_08_TextInputCallbackTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9536C56B2B865DD600B2DFDD /* AA_08_TextInputCallbackTest.swift */; };
959D7D98290B4B9200A1F22F /* AA-05-DeviceBindingCallbackTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 959D7D97290B4B9200A1F22F /* AA-05-DeviceBindingCallbackTest.swift */; };
95E180B42992A6F20087457D /* AA-06-DeviceSigningVerifierCallbackTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95E180B32992A6F20087457D /* AA-06-DeviceSigningVerifierCallbackTest.swift */; };
A53723D12AE80A5D0047B809 /* TelephonyCollectorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A53723D02AE80A5D0047B809 /* TelephonyCollectorTests.swift */; };
3AB062FA2AE6224D00C4B47C /* FRAppIntegrityKeysTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AB062F92AE6224D00C4B47C /* FRAppIntegrityKeysTests.swift */; };
A5950A2A27EA205B00EDEFE4 /* SSLPinningTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5950A2927EA205B00EDEFE4 /* SSLPinningTests.swift */; };
D512CD41240DC41E00AF520E /* FRRestClient.swift in Sources */ = {isa = PBXBuildFile; fileRef = D512CD40240DC41E00AF520E /* FRRestClient.swift */; };
D513F17524DA6B490042228B /* AuthApiError.swift in Sources */ = {isa = PBXBuildFile; fileRef = D513F17424DA6B490042228B /* AuthApiError.swift */; };
Expand Down Expand Up @@ -333,6 +336,8 @@
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
1B6037E52B505924009090DF /* TextInputCallback.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TextInputCallback.swift; sourceTree = "<group>"; };
1B85DA122B85208C0023E953 /* TextInputCallbackTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextInputCallbackTests.swift; sourceTree = "<group>"; };
3A1B43CF284510B700EAFC9D /* AtomicDictionary.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AtomicDictionary.swift; sourceTree = "<group>"; };
3A1B43D2284524B900EAFC9D /* AtomicDictionaryTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AtomicDictionaryTests.swift; sourceTree = "<group>"; };
3A3E785A2AAF6BE8007962B7 /* FRAppIntegrityCallback.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FRAppIntegrityCallback.swift; sourceTree = "<group>"; };
Expand All @@ -345,10 +350,11 @@
3A53E4D92A153AF200E17DDF /* PolicyAdviceCreatorTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PolicyAdviceCreatorTests.swift; sourceTree = "<group>"; };
3A67B8822AD83946003331C5 /* FRAppIntegrityKeys.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FRAppIntegrityKeys.swift; sourceTree = "<group>"; };
3A6D26662A1345400099D877 /* PolicyAdviceCreator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PolicyAdviceCreator.swift; sourceTree = "<group>"; };
3AB062F92AE6224D00C4B47C /* FRAppIntegrityKeysTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FRAppIntegrityKeysTests.swift; sourceTree = "<group>"; };
9536C56B2B865DD600B2DFDD /* AA_08_TextInputCallbackTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AA_08_TextInputCallbackTest.swift; sourceTree = "<group>"; };
959D7D97290B4B9200A1F22F /* AA-05-DeviceBindingCallbackTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "AA-05-DeviceBindingCallbackTest.swift"; sourceTree = "<group>"; };
95E180B32992A6F20087457D /* AA-06-DeviceSigningVerifierCallbackTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "AA-06-DeviceSigningVerifierCallbackTest.swift"; sourceTree = "<group>"; };
A53723D02AE80A5D0047B809 /* TelephonyCollectorTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TelephonyCollectorTests.swift; sourceTree = "<group>"; };
3AB062F92AE6224D00C4B47C /* FRAppIntegrityKeysTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FRAppIntegrityKeysTests.swift; sourceTree = "<group>"; };
A5950A2927EA205B00EDEFE4 /* SSLPinningTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SSLPinningTests.swift; sourceTree = "<group>"; };
D5015FEE24996AE50025FEB6 /* MetadataCallbackTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MetadataCallbackTests.swift; sourceTree = "<group>"; };
D5054B4D244680C3007FBA92 /* DeviceProfileCallbackTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeviceProfileCallbackTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -816,6 +822,7 @@
D58BC38E2602A47600254654 /* IdPCallbackTests.swift */,
D588649126312D2000EAFE4E /* CallbackConstantsTests.swift */,
3A4B46DD2AB38BA6009E7171 /* FRAppIntegrityCallbackTests.swift */,
1B85DA122B85208C0023E953 /* TextInputCallbackTests.swift */,
);
path = Callback;
sourceTree = "<group>";
Expand Down Expand Up @@ -1049,6 +1056,7 @@
D53A8055262789E40093B1CA /* WebAuthnRegistrationCallback.swift */,
D586CF4123358EDF007A2194 /* TermsAndConditionsCallback.swift */,
D586CF4223358EDF007A2194 /* NameCallback.swift */,
1B6037E52B505924009090DF /* TextInputCallback.swift */,
D586CF4323358EDF007A2194 /* PasswordCallback.swift */,
D586CF4423358EDF007A2194 /* MultipleValuesCallback.swift */,
D586CF4523358EDF007A2194 /* PollingWaitCallback.swift */,
Expand Down Expand Up @@ -1190,6 +1198,7 @@
959D7D97290B4B9200A1F22F /* AA-05-DeviceBindingCallbackTest.swift */,
95E180B32992A6F20087457D /* AA-06-DeviceSigningVerifierCallbackTest.swift */,
3A4B46E32AB95B3D009E7171 /* AA_07_AppIntegrityTest.swift */,
9536C56B2B865DD600B2DFDD /* AA_08_TextInputCallbackTest.swift */,
);
path = "Callback-Live";
sourceTree = "<group>";
Expand Down Expand Up @@ -1734,6 +1743,7 @@
D586CF9223358EE0007A2194 /* TermsAndConditionsCallback.swift in Sources */,
D53A804D262789BD0093B1CA /* Client.swift in Sources */,
D586CFB023358EE0007A2194 /* OIDC.swift in Sources */,
1B6037E62B505924009090DF /* TextInputCallback.swift in Sources */,
D53A8057262789E40093B1CA /* WebAuthnCallback.swift in Sources */,
D513F17524DA6B490042228B /* AuthApiError.swift in Sources */,
D5C8641A252E880D00268F06 /* OAuth2Error.swift in Sources */,
Expand Down Expand Up @@ -1938,7 +1948,9 @@
D5791BD425F87DE8004B487A /* TokenErrorTests.swift in Sources */,
D5791BD525F87DE8004B487A /* AuthApiErrorTests.swift in Sources */,
D5791BD625F87DE8004B487A /* BrowserErrorTests.swift in Sources */,
9536C56C2B865DD600B2DFDD /* AA_08_TextInputCallbackTest.swift in Sources */,
D5791BD725F87DE8004B487A /* OAuth2ErrorTests.swift in Sources */,
1B85DA132B85208C0023E953 /* TextInputCallbackTests.swift in Sources */,
D5791BD825F87DE8004B487A /* FRAuthTests.swift in Sources */,
D5791BD925F87DE8004B487A /* FRSessionTests.swift in Sources */,
D5791BDA25F87DE8004B487A /* SessionManagerTests.swift in Sources */,
Expand Down
5 changes: 4 additions & 1 deletion FRAuth/FRAuth/Callbacks/CallbackFactory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// CallbackFactory.swift
// FRAuth
//
// Copyright (c) 2019-2023 ForgeRock. All rights reserved.
// Copyright (c) 2019-2024 ForgeRock. All rights reserved.
//
// This software may be modified and distributed under the terms
// of the MIT license. See the LICENSE file for details.
Expand Down Expand Up @@ -38,6 +38,8 @@ import Foundation
19. WebAuthnAuthenticationCallback
20. IdPCallback
21. SelectIdPCallback
22. FRAppIntegrityCallback
23. TextInputCallback
*/
@objc(FRCallbackFactory)
public class CallbackFactory: NSObject {
Expand Down Expand Up @@ -80,6 +82,7 @@ public class CallbackFactory: NSObject {
CallbackType.IdPCallback.rawValue: IdPCallback.self,
CallbackType.SelectIdPCallback.rawValue: SelectIdPCallback.self,
CallbackType.FRAppIntegrityCallback.rawValue: FRAppIntegrityCallback.self,
CallbackType.TextInputCallback.rawValue: TextInputCallback.self,
]
}

Expand Down
51 changes: 51 additions & 0 deletions FRAuth/FRAuth/Callbacks/TextInputCallback.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
//
// TextInputCallback.swift
// FRAuth
//
// Copyright (c) 2024 ForgeRock. All rights reserved.
//
// This software may be modified and distributed under the terms
// of the MIT license. See the LICENSE file for details.
//

import Foundation

/**
TextInputCallback is a representation of OpenAM's TextInputCallback to collect single user input; It is typically used to collect any text input for the authentication flow.
*/
@objc(FRTextInputCallback)
public class TextInputCallback: SingleValueCallback {

private var defaultText: String?

// MARK: - Init

/// Designated initialization method for TextInputCallback
///
/// - Parameter json: JSON object of TextInputCallback
/// - Throws: AuthError.invalidCallbackResponse for invalid callback response
required init(json: [String : Any]) throws {
try super.init(json: json)

// Validate prompt value for the callback
guard let _ = self.prompt else {
throw AuthError.invalidCallbackResponse(String(describing: json))
}

if let outputs = json[CBConstants.output] as? [[String: Any]] {
for output in outputs {
if let outputName = output[CBConstants.name] as? String, let outputValue = output[CBConstants.value] as? String, outputName == CBConstants.defaultText {
self.defaultText = outputValue
}
}
}
}

public func getDefaultText() -> String? {
return self.defaultText
}

public func setValue(_ val: String) {
self._value = val
}
}
8 changes: 7 additions & 1 deletion FRAuth/FRAuth/Constants/CallbackConstants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// CallbackConstants.swift
// FRAuth
//
// Copyright (c) 2019-2023 ForgeRock. All rights reserved.
// Copyright (c) 2019-2024 ForgeRock. All rights reserved.
//
// This software may be modified and distributed under the terms
// of the MIT license. See the LICENSE file for details.
Expand Down Expand Up @@ -94,6 +94,7 @@ enum CallbackType: String {
case DeviceBindingCallback = "DeviceBindingCallback"
case DeviceSigningVerifierCallback = "DeviceSigningVerifierCallback"
case FRAppIntegrityCallback = "AppIntegrityCallback"
case TextInputCallback = "TextInputCallback"
}

/// CBConstants is mainly responsible to maintain all constant values related to Callback implementation
Expand Down Expand Up @@ -252,3 +253,8 @@ extension CBConstants {
static let keyId = "keyId"
static let clientData = "clientData"
}

// MARK: - TextInputCallback
extension CBConstants {
static let defaultText: String = "defaultText"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
//
// AA_08_TextInputCallbackTest.swift
// FRAuthTests
//
// Copyright (c) 2024 ForgeRock. All rights reserved.
//
// This software may be modified and distributed under the terms
// of the MIT license. See the LICENSE file for details.
//

import XCTest
@testable import FRAuth

class AA_08_TextInputCallbackTest: CallbackBaseTest {

override func setUp() {
super.setUp()
self.config.authServiceName = "TextInputCallbackTest"
}

func test_01_text_input_callback() {
var currentNode: Node?

do {
try currentNode = fulfillUsernamePasswordNodes()
} catch AuthError.invalidCallbackResponse {
XCTFail("Expected at least one node after username/password nodes, but got nothing!")
return
} catch {
XCTFail("Unexpected error occured!")
return
}

// We expect TextInputCallback here. Assert its properties. . .
for callback in currentNode!.callbacks {
if callback is TextInputCallback, let textInputCallback = callback as? TextInputCallback {
XCTAssertEqual(textInputCallback.prompt, "What is your username?")
XCTAssertEqual(textInputCallback.getDefaultText(), "ForgerRocker")

textInputCallback.setValue(config.username)
}
else {
XCTFail("Received unexpected callback \(callback)")
}
}

var ex = self.expectation(description: "Submit the text input callback and continue...")
currentNode?.next { (token: AccessToken?, node, error) in
// Validate result
XCTAssertNotNil(node) // We expect Message node with "Success"
XCTAssertNil(error)
XCTAssertNil(token)
currentNode = node
ex.fulfill()
}
waitForExpectations(timeout: 60, handler: nil)

guard let node = currentNode else {
XCTFail("Test Failed: Expected TextOutputCallback and ConfirmationCallback (returned by Message node), but got nothing...")
return
}

for callback in node.callbacks {
if callback is TextOutputCallback, let textOutputCallback = callback as? TextOutputCallback {
XCTAssertEqual(textOutputCallback.message, "Success")
}
else if callback is ConfirmationCallback, let confirmationCallback = callback as? ConfirmationCallback {
confirmationCallback.value = 0
}
else {
XCTFail("Received unexpected callback \(callback)")
}
}

ex = self.expectation(description: "Submit value for the ConfirmationCallback and continue...")
currentNode?.next { (token: AccessToken?, node, error) in
XCTAssertNil(node)
XCTAssertNil(error)
XCTAssertNotNil(token)
ex.fulfill()
}
waitForExpectations(timeout: 60, handler: nil)

XCTAssertNotNil(FRUser.currentUser)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// CallbackConstantsTests.swift
// FRAuthTests
//
// Copyright (c) 2021 ForgeRock. All rights reserved.
// Copyright (c) 2021-2024 ForgeRock. All rights reserved.
//
// This software may be modified and distributed under the terms
// of the MIT license. See the LICENSE file for details.
Expand Down Expand Up @@ -59,6 +59,10 @@ class CallbackConstantsTests: FRBaseTestCase {
XCTAssertEqual(callbackType.rawValue, "IdPCallback")
callbackType = .SelectIdPCallback
XCTAssertEqual(callbackType.rawValue, "SelectIdPCallback")
callbackType = .FRAppIntegrityCallback
XCTAssertEqual(callbackType.rawValue, "AppIntegrityCallback")
callbackType = .TextInputCallback
XCTAssertEqual(callbackType.rawValue, "TextInputCallback")
}


Expand Down
Loading
Loading