Skip to content

Commit b278a3b

Browse files
committed
Fix LoginExternal passing hostname instead of full OIDC URL, surface auth error codes
1 parent cd08de7 commit b278a3b

File tree

3 files changed

+34
-10
lines changed

3 files changed

+34
-10
lines changed

lib/Ziti.swift

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -656,10 +656,13 @@ import CZitiPrivate
656656

657657
case .CannotContinue:
658658
completed = true
659-
let detail = authEvent.detail.isEmpty ? "authentication cannot continue" : authEvent.detail
660-
log.error("queryProviders: \(detail)", function:"runQueryProviders()")
659+
let msg = !authEvent.error.isEmpty ? authEvent.error
660+
: !authEvent.detail.isEmpty ? authEvent.detail
661+
: "authentication cannot continue"
662+
let code = !authEvent.errorCode.isEmpty ? authEvent.errorCode : nil
663+
log.error("queryProviders: \(msg) (errorCode=\(code ?? "nil"))", function:"runQueryProviders()")
661664
ziti.shutdown()
662-
cb(nil, ZitiError(detail))
665+
cb(nil, ZitiError(msg, errorCodeString: code))
663666

664667
default:
665668
break
@@ -786,13 +789,24 @@ import CZitiPrivate
786789
}
787790

788791
case .LoginExternal:
789-
onAuth(authEvent.detail)
792+
// detail is just the hostname or signer name, not the full OIDC URL.
793+
// Kick off the OIDC flow to get the real auth URL via the launch callback.
794+
ziti.extAuthStatusCallback = { _, url, _ in
795+
log.info("\(modeLabel) extAuth URL: \(url)", function:"runEnrollTo()")
796+
onAuth(url)
797+
}
798+
ziti.perform {
799+
ziti_ext_auth(ziti.ztx, Ziti.onExtAuthStatus, ziti.toVoidPtr())
800+
}
790801

791802
case .CannotContinue:
792-
let detail = authEvent.detail.isEmpty ? "authentication cannot continue" : authEvent.detail
793-
log.error("\(modeLabel): \(detail)", function:"runEnrollTo()")
803+
let msg = !authEvent.error.isEmpty ? authEvent.error
804+
: !authEvent.detail.isEmpty ? authEvent.detail
805+
: "authentication cannot continue"
806+
let code = !authEvent.errorCode.isEmpty ? authEvent.errorCode : nil
807+
log.error("\(modeLabel): \(msg) (errorCode=\(code ?? "nil"))", function:"runEnrollTo()")
794808
ziti.shutdown()
795-
enrollCallback(nil, ZitiError(detail))
809+
enrollCallback(nil, ZitiError(msg, errorCodeString: code))
796810

797811
default:
798812
break

lib/ZitiError.swift

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,22 @@ import Foundation
1717

1818
/// Class used for passing information about error conditions encountered while using Ziti
1919
public class ZitiError : NSError, @unchecked Sendable {
20+
21+
/// Machine-parseable error code string from the controller (e.g. "ENROLLMENT_IDENTITY_ALREADY_ENROLLED")
22+
@objc public let errorCodeString:String?
23+
2024
/// Initialize a ZitiError instance
2125
/// - Parameters:
2226
/// - desc: error description
23-
/// - errorCode: error code
24-
/// - userInfo: user info dictionary
25-
init(_ desc:String, errorCode:Int=Int(-1)) {
27+
/// - errorCode: numeric error code
28+
/// - errorCodeString: machine-parseable error code string from the controller
29+
init(_ desc:String, errorCode:Int=Int(-1), errorCodeString:String?=nil) {
30+
self.errorCodeString = errorCodeString
2631
super.init(domain: "ZitiError", code: errorCode,
2732
userInfo: [NSLocalizedDescriptionKey:NSLocalizedString(desc, comment: "")])
2833
}
2934
required init?(coder: NSCoder) {
35+
self.errorCodeString = nil
3036
fatalError("init(coder:) has not been implemented")
3137
}
3238
}

lib/ZitiEvent.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,9 @@ import CZitiPrivate
271271
/// The authentication detail
272272
@objc public var detail:String
273273

274+
/// Error message (set when action is CannotContinue)
275+
@objc public var error:String
276+
274277
/// Machine-parseable error code from the controller (e.g. "ENROLLMENT_IDENTITY_ALREADY_ENROLLED")
275278
@objc public var errorCode:String
276279

@@ -281,6 +284,7 @@ import CZitiPrivate
281284
action = AuthAction(cEvent.action)
282285
type = cEvent.type != nil ? String(cString: cEvent.type) : ""
283286
detail = cEvent.detail != nil ? String(cString: cEvent.detail) : ""
287+
error = cEvent.error != nil ? String(cString: cEvent.error) : ""
284288
errorCode = cEvent.error_code != nil ? String(cString: cEvent.error_code) : ""
285289
providers = []
286290
if var ptr = cEvent.providers {

0 commit comments

Comments
 (0)