Skip to content

Commit e8fd454

Browse files
Send the Device Token in a cookie HTTP request header (#165)
Supplying the deviceToken to the server within the HTTP request body is deprecated, and no longer supported. This update is to send the value through the appropriate cookie header value instead.
1 parent 79e1a3a commit e8fd454

File tree

3 files changed

+41
-5
lines changed

3 files changed

+41
-5
lines changed

OktaAuthSdk.podspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = 'OktaAuthSdk'
3-
s.version = '2.4.4'
3+
s.version = '2.4.5'
44
s.summary = 'SDK for Okta native authentication.'
55
s.description = <<-DESC
66
Integrate your native app with Okta.

Source/RestAPI/OktaAPI.swift

+19-4
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,30 @@ open class OktaAPI {
5252
bodyParams["relayState"] = relayState
5353
bodyParams["options"] = ["multiOptionalFactorEnroll": multiOptionalFactorEnroll,
5454
"warnBeforePasswordExpired": warnBeforePasswordExpired]
55-
var context: [String: String] = [:]
56-
context["deviceToken"] = deviceToken
57-
bodyParams["context"] = context
5855
bodyParams["token"] = token
5956
req.bodyParams = bodyParams
57+
58+
var additionalHeaders = req.additionalHeaders ?? [:]
59+
if let deviceToken = deviceToken {
60+
var cookies = ["DT=\(deviceToken)"]
61+
if let cookieHeader = req.additionalHeaders?["Cookie"] as? String {
62+
cookies.append(contentsOf: cookieHeader
63+
.components(separatedBy: ";")
64+
.map({ $0.trimmingCharacters(in: .whitespaces) }))
65+
}
66+
67+
additionalHeaders["Cookie"] = cookies.joined(separator: "; ")
68+
}
69+
6070

6171
if let deviceFingerprint = deviceFingerprint {
62-
req.additionalHeaders = ["X-Device-Fingerprint": deviceFingerprint]
72+
additionalHeaders["X-Device-Fingerprint"] = deviceFingerprint
6373
}
74+
75+
if !additionalHeaders.isEmpty {
76+
req.additionalHeaders = additionalHeaders
77+
}
78+
6479
req.run()
6580
return req
6681
}

Tests/RestAPI/OktaAPITests.swift

+21
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,27 @@ class OktaAPITests : XCTestCase {
4444
wait(for: [exp], timeout: 60.0)
4545
}
4646

47+
func testPrimaryAuthenticationWithDeviceToken() {
48+
let username = "username"
49+
let password = "password"
50+
let deviceToken = "abcd123"
51+
52+
let exp = XCTestExpectation()
53+
api.commonCompletion = { req, _ in
54+
XCTAssertEqual(req.baseURL, self.url)
55+
XCTAssertEqual(req.path, "/api/v1/authn")
56+
XCTAssertEqual(req.bodyParams?["username"] as? String, username)
57+
XCTAssertEqual(req.bodyParams?["password"] as? String, password)
58+
XCTAssertNil(req.bodyParams?["context"])
59+
XCTAssertEqual(req.additionalHeaders?["Cookie"], "DT=\(deviceToken)")
60+
exp.fulfill()
61+
}
62+
63+
api.primaryAuthentication(username: username, password: password, deviceToken: deviceToken)
64+
65+
wait(for: [exp], timeout: 60.0)
66+
}
67+
4768
func testPrimaryAuthenticationWithDeviceFingerprint() {
4869
let username = "username"
4970
let password = "password"

0 commit comments

Comments
 (0)