Skip to content

Commit f7e0ba5

Browse files
authored
Fix a regression where DirectAuth OOB channel_hint is missing (#253)
* Fix a regression where DirectAuth OOB channel_hint is missing * Ensure the mock URLSession yields the thread before returning to avoid flaky tests
1 parent 408b899 commit f7e0ba5

4 files changed

Lines changed: 28 additions & 0 deletions

File tree

Sources/OktaDirectAuth/Internal/Requests/ChallengeRequest.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@ struct ChallengeRequest: AuthenticationFlowRequest {
2020
let clientConfiguration: OAuth2Client.Configuration
2121
let context: Flow.Context
2222
let mfaToken: String
23+
let channel: DirectAuthenticationFlow.OOBChannel?
2324
let challengeTypesSupported: [GrantType]
2425

2526
init(openIdConfiguration: OpenIdConfiguration,
2627
clientConfiguration: OAuth2Client.Configuration,
2728
context: DirectAuthenticationFlow.Context,
2829
mfaToken: String,
30+
channel: DirectAuthenticationFlow.OOBChannel?,
2931
challengeTypesSupported: [GrantType]) throws
3032
{
3133
guard let url = openIdConfiguration.challengeEndpoint else {
@@ -36,6 +38,7 @@ struct ChallengeRequest: AuthenticationFlowRequest {
3638
self.clientConfiguration = clientConfiguration
3739
self.context = context
3840
self.mfaToken = mfaToken
41+
self.channel = channel
3942
self.challengeTypesSupported = challengeTypesSupported
4043
}
4144

@@ -87,6 +90,10 @@ extension ChallengeRequest: APIRequest, APIRequestBody {
8790
result["client_id"] = clientConfiguration.clientId
8891
}
8992

93+
if let channel {
94+
result["channel_hint"] = channel
95+
}
96+
9097
return result
9198
}
9299
}

Sources/OktaDirectAuth/Internal/Step Handlers/OOBStepHandler.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ final class OOBStepHandler<Factor: AuthenticationFactor>: StepHandler {
103103
clientConfiguration: flow.client.configuration,
104104
context: context,
105105
mfaToken: mfaToken,
106+
channel: channel,
106107
challengeTypesSupported: [grantType])
107108
let response = try await request.send(to: flow.client)
108109
guard let oobResponse = response.result.oobResponse else {

Tests/OktaDirectAuthTests/RequestTests.swift

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ final class RequestTests: XCTestCase {
143143
scope: "openid profile"),
144144
context: .init(),
145145
mfaToken: "abcd123",
146+
channel: nil,
146147
challengeTypesSupported: [.password, .oob])
147148
XCTAssertEqual(request.bodyParameters?.stringComponents,
148149
[
@@ -151,6 +152,23 @@ final class RequestTests: XCTestCase {
151152
"challenge_types_supported": "password urn:okta:params:oauth:grant-type:oob"
152153
])
153154

155+
// Channel Hint
156+
request = try .init(openIdConfiguration: openIdConfiguration,
157+
clientConfiguration: .init(issuerURL: issuer,
158+
clientId: "theClientId",
159+
scope: "openid profile"),
160+
context: .init(),
161+
mfaToken: "abcd123",
162+
channel: .push,
163+
challengeTypesSupported: [.oobMFA])
164+
XCTAssertEqual(request.bodyParameters?.stringComponents,
165+
[
166+
"client_id": "theClientId",
167+
"mfa_token": "abcd123",
168+
"channel_hint": "push",
169+
"challenge_types_supported": "http://auth0.com/oauth/grant-type/mfa-oob"
170+
])
171+
154172
// Client Secret authentication
155173
request = try .init(openIdConfiguration: openIdConfiguration,
156174
clientConfiguration: .init(issuerURL: issuer,
@@ -159,6 +177,7 @@ final class RequestTests: XCTestCase {
159177
authentication: .clientSecret("supersecret")),
160178
context: .init(),
161179
mfaToken: "abcd123",
180+
channel: nil,
162181
challengeTypesSupported: [.password, .oob])
163182
XCTAssertEqual(request.bodyParameters?.stringComponents,
164183
[

Tests/TestCommon/URLSessionMock.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ class URLSessionMock: URLSessionProtocol, @unchecked Sendable {
128128
try await Task.sleep(delay: delay)
129129
}
130130

131+
await MainActor.yield()
131132
guard let data = call?.data,
132133
let response = call?.response
133134
else {

0 commit comments

Comments
 (0)