Skip to content

Commit

Permalink
Ensure the authentication flow config is included in all appropriate …
Browse files Browse the repository at this point in the history
…requests
  • Loading branch information
mikenachbaur-okta committed Dec 11, 2024
1 parent adc1a42 commit 7817737
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 4 deletions.
9 changes: 9 additions & 0 deletions Sources/OktaDirectAuth/Extensions/Array+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ import Foundation

extension Array where Element == GrantType {
/// The list of all grants that the Direct Authentication SDK supports.
///
/// Currently this library supports the following authentication grant types:
/// * ``GrantType.password``
/// * ``GrantType.oob``
/// * ``GrantType.otp``
/// * ``GrantType.webAuthn``
/// * ``GrantType.oobMFA``
/// * ``GrantType.otpMFA``
/// * ``GrantType.webAuthnMFA``
public static var directAuth: [GrantType] {
[ .password, .oob, .otp, .oobMFA, .otpMFA, .webAuthn, .webAuthnMFA ]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@ extension OpenIdConfiguration {
struct ChallengeRequest {
let url: URL
let clientConfiguration: OAuth2Client.Configuration
let authenticationFlowConfiguration: (any AuthenticationFlowConfiguration)?
let mfaToken: String
let challengeTypesSupported: [GrantType]

init(openIdConfiguration: OpenIdConfiguration,
clientConfiguration: OAuth2Client.Configuration,
authenticationFlowConfiguration: (any AuthenticationFlowConfiguration)?,
mfaToken: String,
challengeTypesSupported: [GrantType]) throws
{
Expand All @@ -36,6 +38,7 @@ struct ChallengeRequest {

self.url = url
self.clientConfiguration = clientConfiguration
self.authenticationFlowConfiguration = authenticationFlowConfiguration
self.mfaToken = mfaToken
self.challengeTypesSupported = challengeTypesSupported
}
Expand Down Expand Up @@ -85,6 +88,7 @@ extension ChallengeRequest: APIRequest, APIRequestBody {
]

result.merge(clientConfiguration.authentication)
result.merge(authenticationFlowConfiguration)

return result
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,14 @@ struct OOBResponse: Codable, HasTokenParameters {
struct OOBAuthenticateRequest {
let url: URL
let clientConfiguration: OAuth2Client.Configuration
let authenticationFlowConfiguration: (any AuthenticationFlowConfiguration)?
let loginHint: String
let channelHint: DirectAuthenticationFlow.OOBChannel
let challengeHint: GrantType

init(openIdConfiguration: OpenIdConfiguration,
clientConfiguration: OAuth2Client.Configuration,
authenticationFlowConfiguration: (any AuthenticationFlowConfiguration)?,
loginHint: String,
channelHint: DirectAuthenticationFlow.OOBChannel,
challengeHint: GrantType) throws
Expand All @@ -60,6 +62,7 @@ struct OOBAuthenticateRequest {

self.url = url
self.clientConfiguration = clientConfiguration
self.authenticationFlowConfiguration = authenticationFlowConfiguration
self.loginHint = loginHint
self.channelHint = channelHint
self.challengeHint = challengeHint
Expand Down Expand Up @@ -87,6 +90,7 @@ extension OOBAuthenticateRequest: APIRequest, APIRequestBody {
]

result.merge(clientConfiguration.authentication)
result.merge(authenticationFlowConfiguration)

return result
}
Expand Down
8 changes: 4 additions & 4 deletions Sources/OktaDirectAuth/Internal/Requests/TokenRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,30 @@ import AuthFoundation
struct TokenRequest {
let openIdConfiguration: OpenIdConfiguration
let clientConfiguration: OAuth2Client.Configuration
let authenticationFlowConfiguration: (any AuthenticationFlowConfiguration)?
let currentStatus: DirectAuthenticationFlow.Status?
let loginHint: String?
let factor: any AuthenticationFactor
let intent: DirectAuthenticationFlow.Intent
let parameters: (any HasTokenParameters)?
let authenticationFlowConfiguration: (any AuthenticationFlowConfiguration)?

init(openIdConfiguration: OpenIdConfiguration,
clientConfiguration: OAuth2Client.Configuration,
authenticationFlowConfiguration: (any AuthenticationFlowConfiguration)?,
currentStatus: DirectAuthenticationFlow.Status?,
loginHint: String? = nil,
factor: any AuthenticationFactor,
intent: DirectAuthenticationFlow.Intent,
parameters: (any HasTokenParameters)? = nil,
authenticationFlowConfiguration: (any AuthenticationFlowConfiguration)? = nil)
parameters: (any HasTokenParameters)? = nil)
{
self.openIdConfiguration = openIdConfiguration
self.clientConfiguration = clientConfiguration
self.authenticationFlowConfiguration = authenticationFlowConfiguration
self.currentStatus = currentStatus
self.loginHint = loginHint
self.factor = factor
self.intent = intent
self.parameters = parameters
self.authenticationFlowConfiguration = authenticationFlowConfiguration
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ import AuthFoundation
struct WebAuthnChallengeRequest {
let url: URL
let clientConfiguration: OAuth2Client.Configuration
let authenticationFlowConfiguration: (any AuthenticationFlowConfiguration)?
let loginHint: String?
let mfaToken: String?

init(openIdConfiguration: OpenIdConfiguration,
clientConfiguration: OAuth2Client.Configuration,
authenticationFlowConfiguration: (any AuthenticationFlowConfiguration)?,
loginHint: String? = nil,
mfaToken: String? = nil) throws
{
Expand All @@ -30,6 +32,7 @@ struct WebAuthnChallengeRequest {

self.url = url
self.clientConfiguration = clientConfiguration
self.authenticationFlowConfiguration = authenticationFlowConfiguration
self.loginHint = loginHint
self.mfaToken = mfaToken
}
Expand All @@ -56,6 +59,7 @@ extension WebAuthnChallengeRequest: APIRequest, APIRequestBody {
}

result.merge(clientConfiguration.authentication)
result.merge(authenticationFlowConfiguration)

return result
}
Expand Down

0 comments on commit 7817737

Please sign in to comment.