diff --git a/Source/OktaAuthSdk.swift b/Source/OktaAuthSdk.swift index 9fee242..e8721c8 100644 --- a/Source/OktaAuthSdk.swift +++ b/Source/OktaAuthSdk.swift @@ -17,12 +17,16 @@ public class OktaAuthSdk { public class func authenticate(with url: URL, username: String, password: String?, + deviceToken: String?, + deviceFingerprint: String?, onStatusChange: @escaping (_ newStatus: OktaAuthStatus) -> Void, onError: @escaping (_ error: OktaError) -> Void) { let unauthenticatedStatus = OktaAuthStatusUnauthenticated(oktaDomain: url) unauthenticatedStatus.authenticate(username: username, password: password ?? "", + deviceToken: deviceToken ?? "", + deviceFingerprint: deviceFingerprint ?? "", onStatusChange:onStatusChange, onError:onError) } diff --git a/Source/Statuses/OktaAuthStatusUnauthenticated.swift b/Source/Statuses/OktaAuthStatusUnauthenticated.swift index 5194331..9d3b6df 100644 --- a/Source/Statuses/OktaAuthStatusUnauthenticated.swift +++ b/Source/Statuses/OktaAuthStatusUnauthenticated.swift @@ -21,12 +21,15 @@ open class OktaAuthStatusUnauthenticated : OktaAuthStatus { open func authenticate(username: String, password: String, + deviceToken: String, + deviceFingerprint: String, onStatusChange: @escaping (_ newStatus: OktaAuthStatus) -> Void, onError: @escaping (_ error: OktaError) -> Void) { restApi.primaryAuthentication(username: username, password: password, - deviceFingerprint: nil) + deviceToken: deviceToken, + deviceFingerprint: deviceFingerprint) { result in self.handleServerResponse(result, onStatusChanged: onStatusChange, diff --git a/Tests/E2E/E2ETests.swift b/Tests/E2E/E2ETests.swift index 8a3b5c9..8ce5dfe 100644 --- a/Tests/E2E/E2ETests.swift +++ b/Tests/E2E/E2ETests.swift @@ -45,7 +45,7 @@ class E2ETests: XCTestCase { func testPrimaryAuthFlowSuccess() { let ex = expectation(description: "Operation should succeed!") - OktaAuthSdk.authenticate(with: URL(string: urlString)!, username: primaryAuthUser!.username, password: primaryAuthUser!.password, onStatusChange: { status in + OktaAuthSdk.authenticate(with: URL(string: urlString)!, username: primaryAuthUser!.username, password: primaryAuthUser!.password, deviceToken: "deviceToken", deviceFingerprint: nil, onStatusChange: { status in XCTAssertTrue(status.statusType == .success) self.verifyBasicInfoForStatus(status: status) let successStatus = status as! OktaAuthStatusSuccess @@ -61,7 +61,7 @@ class E2ETests: XCTestCase { func testPrimaryAuthFlowFailure() { let ex = expectation(description: "Operation should fail!") - OktaAuthSdk.authenticate(with: URL(string: urlString)!, username: primaryAuthUser!.username, password: "Wrong password", onStatusChange: { status in + OktaAuthSdk.authenticate(with: URL(string: urlString)!, username: primaryAuthUser!.username, password: "Wrong password", deviceToken: "deviceToken", deviceFingerprint: nil, onStatusChange: { status in XCTFail("Unexpected status") ex.fulfill() }) { error in @@ -78,7 +78,7 @@ class E2ETests: XCTestCase { func testFactorChallengeSuccess() { var factorRequiredStatus: OktaAuthStatusFactorRequired? let ex = expectation(description: "Operation should succeed!") - OktaAuthSdk.authenticate(with: URL(string: urlString)!, username: factorRequiredUser!.username, password: factorRequiredUser!.password, onStatusChange: { status in + OktaAuthSdk.authenticate(with: URL(string: urlString)!, username: factorRequiredUser!.username, password: factorRequiredUser!.password, deviceToken: "deviceToken", deviceFingerprint: nil, onStatusChange: { status in XCTAssertTrue(status.statusType == .MFARequired) factorRequiredStatus = status as? OktaAuthStatusFactorRequired if let factorRequiredStatus = factorRequiredStatus { @@ -130,7 +130,7 @@ class E2ETests: XCTestCase { var factorEnrollStatus: OktaAuthStatusFactorEnroll? var pushFactor: OktaFactorPush? let ex = expectation(description: "Operation should succeed!") - OktaAuthSdk.authenticate(with: URL(string: urlString)!, username: factorEnrollmentUser!.username, password: factorEnrollmentUser!.password, onStatusChange: { status in + OktaAuthSdk.authenticate(with: URL(string: urlString)!, username: factorEnrollmentUser!.username, password: factorEnrollmentUser!.password, deviceToken: "deviceToken", deviceFingerprint: nil, onStatusChange: { status in XCTAssertTrue(status.statusType == .MFAEnroll) factorEnrollStatus = status as? OktaAuthStatusFactorEnroll if let factorEnrollStatus = factorEnrollStatus { @@ -218,7 +218,7 @@ class E2ETests: XCTestCase { var factorEnrollStatus: OktaAuthStatusFactorEnroll? var smsFactor: OktaFactorSms? let ex = expectation(description: "Operation should succeed!") - OktaAuthSdk.authenticate(with: URL(string: urlString)!, username: factorEnrollmentUser!.username, password: factorEnrollmentUser!.password, onStatusChange: { status in + OktaAuthSdk.authenticate(with: URL(string: urlString)!, username: factorEnrollmentUser!.username, password: factorEnrollmentUser!.password, deviceToken: "deviceToken", deviceFingerprint: nil, onStatusChange: { status in XCTAssertTrue(status.statusType == .MFAEnroll) factorEnrollStatus = status as? OktaAuthStatusFactorEnroll if let factorEnrollStatus = factorEnrollStatus { @@ -257,7 +257,7 @@ class E2ETests: XCTestCase { var factorEnrollStatus: OktaAuthStatusFactorEnroll? var totpFactor: OktaFactorTotp? let ex = expectation(description: "Operation should succeed!") - OktaAuthSdk.authenticate(with: URL(string: urlString)!, username: factorEnrollmentUser!.username, password: factorEnrollmentUser!.password, onStatusChange: { status in + OktaAuthSdk.authenticate(with: URL(string: urlString)!, username: factorEnrollmentUser!.username, password: factorEnrollmentUser!.password, deviceToken: "deviceToken", deviceFingerprint: nil, onStatusChange: { status in XCTAssertTrue(status.statusType == .MFAEnroll) factorEnrollStatus = status as? OktaAuthStatusFactorEnroll if let factorEnrollStatus = factorEnrollStatus { diff --git a/Tests/Statuses/OktaAuthStatusUnauthenticatedTests.swift b/Tests/Statuses/OktaAuthStatusUnauthenticatedTests.swift index 66e568c..4cf298a 100644 --- a/Tests/Statuses/OktaAuthStatusUnauthenticatedTests.swift +++ b/Tests/Statuses/OktaAuthStatusUnauthenticatedTests.swift @@ -25,6 +25,8 @@ class OktaAuthStatusUnauthenticatedTests: XCTestCase { status.authenticate( username: "test", password: "test", + deviceToken: "deviceToken", + deviceFingerprint: "deviceFingerprint", onStatusChange: { status in XCTAssertEqual(AuthStatus.success, status.statusType) ex.fulfill() @@ -48,6 +50,8 @@ class OktaAuthStatusUnauthenticatedTests: XCTestCase { status.authenticate( username: "test", password: "test", + deviceToken: "deviceToken", + deviceFingerprint: "deviceFingerprint", onStatusChange: { status in XCTFail("Unexpected status change: \(status)") ex.fulfill()