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

Added ability to pass device token and device fingerprint #120

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions Source/OktaAuthSdk.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
5 changes: 4 additions & 1 deletion Source/Statuses/OktaAuthStatusUnauthenticated.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
12 changes: 6 additions & 6 deletions Tests/E2E/E2ETests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions Tests/Statuses/OktaAuthStatusUnauthenticatedTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand Down