Skip to content

Commit

Permalink
added sub as local user account if other methods not available; added…
Browse files Browse the repository at this point in the history
… some additional logging
  • Loading branch information
twocanoes committed Dec 14, 2022
1 parent 5bd5f84 commit fd4067d
Show file tree
Hide file tree
Showing 9 changed files with 157 additions and 23 deletions.
2 changes: 1 addition & 1 deletion XCreds/TokenManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ class TokenManager {

}
else {
TCSLogWithMark("got status code of \(response.statusCode)")
TCSLogWithMark("got status code of \(response.statusCode):\(response)")
completion(false,false)

}
Expand Down
99 changes: 99 additions & 0 deletions XCreds/WebView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,105 @@ class WebViewController: NSWindowController {
}
func tokensUpdated(tokens: Creds){
//to be overridden by superclasses
/*
var username:String
let defaultsUsername = UserDefaults.standard.string(forKey: PrefKeys.username.rawValue)
guard let idToken = tokens.idToken else {
TCSLogWithMark("invalid idToken")
return
}
let array = idToken.components(separatedBy: ".")
if array.count != 3 {
TCSLogWithMark("idToken is invalid")
}
let body = array[1]
guard let data = base64UrlDecode(value:body ) else {
TCSLogWithMark("error decoding id token base64")
return
}
let decoder = JSONDecoder()
var idTokenObject:IDToken
do {
idTokenObject = try decoder.decode(IDToken.self, from: data)
}
catch {
TCSLogWithMark("error decoding idtoken::")
TCSLogWithMark("Token:\(body)")
return
}
let idTokenInfo = jwtDecode(value: idToken) //dictionary for mappnigs
// username static map
if let defaultsUsername = defaultsUsername {
username = defaultsUsername
}
else if let idTokenInfo = idTokenInfo, let mapKey = UserDefaults.standard.object(forKey: "map_username") as? String, mapKey.count>0, let mapValue = idTokenInfo[mapKey] as? String {
//we have a mapping for username, so use that.
username = mapValue
TCSLogWithMark("mapped username found: \(username)")
}
else {
var emailString:String
if let email = idTokenObject.email {
emailString=email.lowercased()
}
else if let uniqueName=idTokenObject.unique_name {
emailString=uniqueName
}
else {
TCSLogWithMark("no username found. Using sub.")
emailString=idTokenObject.sub
}
guard let tUsername = emailString.components(separatedBy: "@").first?.lowercased() else {
TCSLogWithMark("email address invalid")
return
}
TCSLogWithMark("username found: \(tUsername)")
username = tUsername
}
//full name
TCSLogWithMark("checking map_fullname")
if let idTokenInfo = idTokenInfo, let mapKey = UserDefaults.standard.object(forKey: "map_fullname") as? String, mapKey.count>0, let mapValue = idTokenInfo[mapKey] as? String {
//we have a mapping so use that.
TCSLogWithMark("full name mapped to: \(mapKey)")
}
else if let firstName = idTokenObject.given_name, let lastName = idTokenObject.family_name {
TCSLogWithMark("firstName: \(firstName)")
TCSLogWithMark("lastName: \(lastName)")
}
//first name
if let idTokenInfo = idTokenInfo, let mapKey = UserDefaults.standard.object(forKey: "map_firstname") as? String, mapKey.count>0, let mapValue = idTokenInfo[mapKey] as? String {
//we have a mapping for username, so use that.
TCSLogWithMark("first name mapped to: \(mapKey)")
}
else if let firstName = idTokenObject.given_name {
TCSLogWithMark("firstName from token: \(firstName)")
}
*/
}
}

Expand Down
33 changes: 25 additions & 8 deletions XCredsLoginPlugIn/LoginWindow/LoginWebViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,7 @@ class LoginWebViewController: WebViewController {

let idTokenInfo = jwtDecode(value: idToken) //dictionary for mappnigs



// username
// username static map
if let defaultsUsername = defaultsUsername {
username = defaultsUsername
}
Expand All @@ -166,11 +164,10 @@ class LoginWebViewController: WebViewController {
else if let uniqueName=idTokenObject.unique_name {
emailString=uniqueName
}
else {
TCSLogWithMark("no username found or invalid")
delegate.denyLogin()
return

else {
TCSLogWithMark("no username found. Using sub.")
emailString=idTokenObject.sub
}
guard let tUsername = emailString.components(separatedBy: "@").first?.lowercased() else {
TCSLogWithMark("email address invalid")
Expand All @@ -184,6 +181,8 @@ class LoginWebViewController: WebViewController {
}

//full name
TCSLogWithMark("checking map_fullname")

if let idTokenInfo = idTokenInfo, let mapKey = UserDefaults.standard.object(forKey: "map_fullname") as? String, mapKey.count>0, let mapValue = idTokenInfo[mapKey] as? String {
//we have a mapping so use that.
TCSLogWithMark("full name mapped to: \(mapKey)")
Expand All @@ -193,6 +192,8 @@ class LoginWebViewController: WebViewController {
}

else if let firstName = idTokenObject.given_name, let lastName = idTokenObject.family_name {
TCSLogWithMark("firstName: \(firstName)")
TCSLogWithMark("lastName: \(lastName)")
delegate.setHint(type: .fullName, hint: "\(firstName) \(lastName)")

}
Expand All @@ -206,10 +207,13 @@ class LoginWebViewController: WebViewController {
}

else if let firstName = idTokenObject.given_name {
TCSLogWithMark("firstName from token: \(firstName)")

delegate.setHint(type: .firstName, hint:firstName)

}
//last name
TCSLogWithMark("checking map_lastname")

if let idTokenInfo = idTokenInfo, let mapKey = UserDefaults.standard.object(forKey: "map_lastname") as? String, mapKey.count>0, let mapValue = idTokenInfo[mapKey] as? String {
//we have a mapping for lastName, so use that.
Expand All @@ -219,9 +223,13 @@ class LoginWebViewController: WebViewController {
}

else if let lastName = idTokenObject.family_name {
TCSLogWithMark("lastName from token: \(lastName)")

delegate.setHint(type: .lastName, hint:lastName)

}
TCSLogWithMark("checking local password for username:\(username) and password length: \(tokens.password.count)");

let isValidPassword = try? PasswordUtils.isLocalPasswordValid(userName: username, userPass: tokens.password)

if isValidPassword==false{
Expand Down Expand Up @@ -299,9 +307,17 @@ class LoginWebViewController: WebViewController {

}
TCSLogWithMark("passing username:\(username), password, and tokens")
TCSLogWithMark("setting kAuthorizationEnvironmentUsername")

delegate.setContextString(type: kAuthorizationEnvironmentUsername, value: username)
TCSLogWithMark("setting kAuthorizationEnvironmentPassword")

delegate.setContextString(type: kAuthorizationEnvironmentPassword, value: tokens.password)
TCSLogWithMark("setting username")

delegate.setHint(type: .user, hint: username)
TCSLogWithMark("setting tokens.password")

delegate.setHint(type: .pass, hint: tokens.password)
// setHint(type: .noMADFirst, hint: user.firstName)
// setHint(type: .noMADLast, hint: user.lastName)
Expand All @@ -311,7 +327,8 @@ class LoginWebViewController: WebViewController {
// delegate.setHint(type: .firstName, hint: idTokenObject.given_name ?? "")
// delegate.setHint(type: .lastName, hint: idTokenObject.family_name ?? "")

delegate.setHint(type: .tokens, hint: [tokens.idToken,tokens.refreshToken,tokens.accessToken])
TCSLogWithMark("setting tokens")
delegate.setHint(type: .tokens, hint: [tokens.idToken ?? "",tokens.refreshToken ?? "",tokens.accessToken ?? ""])
if let resolutionObserver = resolutionObserver {
NotificationCenter.default.removeObserver(resolutionObserver)
}
Expand Down
5 changes: 3 additions & 2 deletions XCredsLoginPlugIn/Mechanisms/XCredsBaseMechanism.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ protocol XCredsMechanismProtocol {
var xcredsFirst: String? {
get {
guard let firstName = getHint(type: .firstName) as? String else {
return nil
return ""
}
os_log("Computed nomadFirst accessed: %{public}@", log: noLoMechlog, type: .debug, firstName)
return firstName
Expand All @@ -77,7 +77,7 @@ protocol XCredsMechanismProtocol {
var xcredsLast: String? {
get {
guard let lastName = getHint(type: .lastName) as? String else {
return nil
return ""
}
os_log("Computed nomadLast accessed: %{public}@", log: noLoMechlog, type: .debug, lastName)
return lastName
Expand Down Expand Up @@ -145,6 +145,7 @@ protocol XCredsMechanismProtocol {

// disallow login
func denyLogin() {
TCSLog("***************** DENYING LOGIN ********************");
TCSLogWithMark("\(#function) \(#file):\(#line)")

let error = mechCallbacks.SetResult(mechEngine, .deny)
Expand Down
2 changes: 1 addition & 1 deletion XCredsLoginPlugIn/Mechanisms/XCredsCreateUser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class XCredsCreateUser: XCredsBaseMechanism {
// customAttributes["dsAttrTypeNative:\(nomadMetaPrefix)_domain"] = nomadDomain!

createUser(shortName: xcredsUser!,
first: xcredsFirst!,
first: xcredsFirst! ,
last: xcredsLast!,
pass: xcredsPass!,
uid: uid,
Expand Down
1 change: 1 addition & 0 deletions XCredsLoginPlugIn/Mechanisms/XCredsLoginMechanism.swift
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ import Cocoa
}
override func denyLogin() {
loginWindowControlsWindowController.close()
TCSLog("***************** DENYING LOGIN ********************");
super.denyLogin()
}
}
28 changes: 22 additions & 6 deletions xCreds.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -868,6 +868,8 @@
MACOSX_DEPLOYMENT_TARGET = 11.0;
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
STRIP_INSTALLED_PRODUCT = NO;
STRIP_SWIFT_SYMBOLS = NO;
SWIFT_OBJC_BRIDGING_HEADER = "XCreds/XCredsLoginPlugin-Bridging-Header.h";
SWIFT_VERSION = 5.0;
};
Expand All @@ -882,6 +884,8 @@
MACOSX_DEPLOYMENT_TARGET = 11.0;
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
STRIP_INSTALLED_PRODUCT = NO;
STRIP_SWIFT_SYMBOLS = NO;
SWIFT_OBJC_BRIDGING_HEADER = "XCreds/XCredsLoginPlugin-Bridging-Header.h";
SWIFT_VERSION = 5.0;
};
Expand All @@ -893,7 +897,7 @@
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 3336;
CURRENT_PROJECT_VERSION = 3345;
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = UXP6YEHSPW;
GENERATE_INFOPLIST_FILE = YES;
Expand All @@ -910,6 +914,8 @@
PRODUCT_BUNDLE_IDENTIFIER = com.twocanoes.XCredsLoginPlugin;
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
STRIP_INSTALLED_PRODUCT = NO;
STRIP_SWIFT_SYMBOLS = NO;
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_OBJC_BRIDGING_HEADER = "XCreds/XCredsLoginPlugin-Bridging-Header.h";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
Expand All @@ -924,7 +930,7 @@
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 3336;
CURRENT_PROJECT_VERSION = 3345;
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = UXP6YEHSPW;
GENERATE_INFOPLIST_FILE = YES;
Expand All @@ -941,6 +947,8 @@
PRODUCT_BUNDLE_IDENTIFIER = com.twocanoes.XCredsLoginPlugin;
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
STRIP_INSTALLED_PRODUCT = NO;
STRIP_SWIFT_SYMBOLS = NO;
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_OBJC_BRIDGING_HEADER = "XCreds/XCredsLoginPlugin-Bridging-Header.h";
SWIFT_VERSION = 5.0;
Expand Down Expand Up @@ -983,7 +991,7 @@
CODE_SIGN_ENTITLEMENTS = "XCreds Login Overlay/XCreds_Login_Overlay.entitlements";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 3336;
CURRENT_PROJECT_VERSION = 3345;
DEVELOPMENT_TEAM = UXP6YEHSPW;
ENABLE_HARDENED_RUNTIME = YES;
GENERATE_INFOPLIST_FILE = YES;
Expand All @@ -999,6 +1007,8 @@
PRODUCT_BUNDLE_IDENTIFIER = "com.twocanoes.XCreds-Login-Overlay";
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
STRIP_INSTALLED_PRODUCT = NO;
STRIP_SWIFT_SYMBOLS = NO;
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_OBJC_BRIDGING_HEADER = "XCreds/XCreds-Bridging-Header.h";
SWIFT_VERSION = 5.0;
Expand All @@ -1013,7 +1023,7 @@
CODE_SIGN_ENTITLEMENTS = "XCreds Login Overlay/XCreds_Login_Overlay.entitlements";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 3336;
CURRENT_PROJECT_VERSION = 3345;
DEVELOPMENT_TEAM = UXP6YEHSPW;
ENABLE_HARDENED_RUNTIME = YES;
GENERATE_INFOPLIST_FILE = YES;
Expand All @@ -1029,6 +1039,8 @@
PRODUCT_BUNDLE_IDENTIFIER = "com.twocanoes.XCreds-Login-Overlay";
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
STRIP_INSTALLED_PRODUCT = NO;
STRIP_SWIFT_SYMBOLS = NO;
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_OBJC_BRIDGING_HEADER = "XCreds/XCreds-Bridging-Header.h";
SWIFT_VERSION = 5.0;
Expand Down Expand Up @@ -1156,7 +1168,7 @@
CODE_SIGN_ENTITLEMENTS = XCreds/xCreds.entitlements;
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 3336;
CURRENT_PROJECT_VERSION = 3345;
DEVELOPMENT_TEAM = UXP6YEHSPW;
ENABLE_HARDENED_RUNTIME = YES;
GENERATE_INFOPLIST_FILE = YES;
Expand All @@ -1171,6 +1183,8 @@
MARKETING_VERSION = 2.2;
PRODUCT_BUNDLE_IDENTIFIER = com.twocanoes.xcreds;
PRODUCT_NAME = "$(TARGET_NAME)";
STRIP_INSTALLED_PRODUCT = NO;
STRIP_SWIFT_SYMBOLS = NO;
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_OBJC_BRIDGING_HEADER = "XCreds/XCreds-Bridging-Header.h";
SWIFT_VERSION = 5.0;
Expand All @@ -1185,7 +1199,7 @@
CODE_SIGN_ENTITLEMENTS = XCreds/xCreds.entitlements;
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 3336;
CURRENT_PROJECT_VERSION = 3345;
DEVELOPMENT_TEAM = UXP6YEHSPW;
ENABLE_HARDENED_RUNTIME = YES;
GENERATE_INFOPLIST_FILE = YES;
Expand All @@ -1200,6 +1214,8 @@
MARKETING_VERSION = 2.2;
PRODUCT_BUNDLE_IDENTIFIER = com.twocanoes.xcreds;
PRODUCT_NAME = "$(TARGET_NAME)";
STRIP_INSTALLED_PRODUCT = NO;
STRIP_SWIFT_SYMBOLS = NO;
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_OBJC_BRIDGING_HEADER = "XCreds/XCreds-Bridging-Header.h";
SWIFT_VERSION = 5.0;
Expand Down
Binary file not shown.

0 comments on commit fd4067d

Please sign in to comment.