Skip to content

Commit

Permalink
Resolves #111 by only refreshing when on cloud login
Browse files Browse the repository at this point in the history
  • Loading branch information
twocanoes committed Nov 15, 2023
1 parent bec80f2 commit ca8e985
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 37 deletions.
6 changes: 4 additions & 2 deletions DefaultsOverride.swift
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,14 @@ public class DefaultsOverride: UserDefaults {
return UserDefaults.standard.double(forKey: defaultName)
}
override public func bool(forKey defaultName: String) -> Bool {
TCSLogWithMark()
TCSLogInfoWithMark("requested override for \(defaultName)")

if let defaultName = cachedPrefs[defaultName] as? Bool {
TCSLogInfoWithMark("override value \(defaultName)")

return defaultName
}
TCSLogWithMark()
TCSLogInfoWithMark("default not overridden")

return UserDefaults.standard.bool(forKey: defaultName)
}
Expand Down
2 changes: 1 addition & 1 deletion Profile Manifest/com.twocanoes.xcreds.plist
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<key>pfm_app_url</key>
<string>https://github.com/twocanoes/xcreds</string>
<key>pfm_description</key>
<string>XCreds 3.2 (5209) OAuth Settings</string>
<string>XCreds 3.3 (5214) OAuth Settings</string>
<key>pfm_documentation_url</key>
<string>https://twocanoes.com/knowledge-base/xcreds-admin-guide/#preferences</string>
<key>pfm_domain</key>
Expand Down
2 changes: 1 addition & 1 deletion XCreds/PasswordUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ class PasswordUtils: NSObject {

case Int(kODErrorCredentialsMethodNotSupported.rawValue):
TCSLogWithMark("credential type not supported: \(userName).")
return .incorrectPassword
return .other("credential type not supported")


default:
Expand Down
2 changes: 1 addition & 1 deletion XCreds/PrefKeys.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Foundation

enum PrefKeys: String {
case clientID, clientSecret, password="xcreds local password",discoveryURL, redirectURI, scopes, accessToken, idToken, refreshToken, tokenEndpoint, expirationDate, invalidToken, refreshRateHours,refreshRateMinutes, showDebug, verifyPassword, shouldShowQuitMenu, shouldShowPreferencesOnStart, shouldSetGoogleAccessTypeToOffline, passwordChangeURL, shouldShowAboutMenu, username, idpHostName, passwordElementID, shouldFindPasswordElement, shouldShowVersionInfo, shouldShowSupportStatus,shouldShowConfigureWifiButton,shouldShowMacLoginButton, loginWindowBackgroundImageURL, shouldShowCloudLoginByDefault, shouldPreferLocalLoginInsteadOfCloudLogin, idpHostNames,autoRefreshLoginTimer, loginWindowWidth, loginWindowHeight, shouldShowRefreshBanner, shouldSwitchToLoginWindowWhenLocked,accounts = "Accounts",
windowSignIn = "WindowSignIn", settingsOverrideScriptPath, localAdminUserName, localAdminPassword, usernamePlaceholder, passwordPlaceholder, shouldShowLocalOnlyCheckbox, shouldShowTokenUpdateStatus, shouldDetectNetworkToDetermineLoginWindow
windowSignIn = "WindowSignIn", settingsOverrideScriptPath, localAdminUserName, localAdminPassword, usernamePlaceholder, passwordPlaceholder, shouldShowLocalOnlyCheckbox, shouldShowTokenUpdateStatus, shouldDetectNetworkToDetermineLoginWindow, showLoginWindowDelaySeconds
//, filePathToPreventShowingUI
case ropgClientID
case ropgClientSecret
Expand Down
18 changes: 14 additions & 4 deletions XCredsLoginPlugIn/Mechanisms/XCredsLoginMechanism.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,12 @@ import Network

}
override func reload() {
TCSLogWithMark("reload in controller")
loginWebViewWindowController?.setupLoginWindowAppearance()

loginWebViewWindowController?.loadPage()
if self.loginWindowType == .cloud {
TCSLogWithMark("reload in controller")
loginWebViewWindowController?.setupLoginWindowAppearance()

loginWebViewWindowController?.loadPage()
}
}
func useAutologin() -> Bool {

Expand Down Expand Up @@ -180,6 +182,14 @@ import Network
allowLogin()
return
}
let showLoginWindowDelaySeconds = DefaultsOverride.standardOverride.integer(forKey: PrefKeys.showLoginWindowDelaySeconds.rawValue)

if showLoginWindowDelaySeconds > 0 {
TCSLogWithMark("Delaying showing window by \(showLoginWindowDelaySeconds) seconds")

sleep(UInt32(showLoginWindowDelaySeconds))
}

selectAndShowLoginWindow()

let isReturning = FileManager.default.fileExists(atPath: "/tmp/xcreds_return")
Expand Down
35 changes: 19 additions & 16 deletions XCredsLoginPlugIn/WifiManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -134,25 +134,28 @@ class WifiManager: CWEventDelegate {

func connectWifi(with network: CWNetwork, password: String?, username: String?, identity: SecIdentity? = nil) -> Bool {
var result = false
do {
TCSLogWithMark("connecting")
currentInterface?.disassociate()

if username != nil && username != "" {
TCSLogWithMark("connecting \(username ?? "<unknown username")")
try currentInterface?.associate(toEnterpriseNetwork: network, identity: identity, username: username, password: password)
} else {
TCSLogWithMark("connecting with password only \(network)")
try currentInterface?.associate(to: network, password: password)
TCSLogWithMark("done associating")
for _ in 1...3 {
do {
TCSLogWithMark("connecting")
currentInterface?.disassociate()

}
result = true
} catch {
TCSLogWithMark("caught error: \(error)")
if username != nil && username != "" {
TCSLogWithMark("connecting \(username ?? "<unknown username")")
try currentInterface?.associate(toEnterpriseNetwork: network, identity: identity, username: username, password: password)
} else {
TCSLogWithMark("connecting with password only \(network)")
try currentInterface?.associate(to: network, password: password)
TCSLogWithMark("done associating")

self.error = error
}
}
result = true
break
} catch {
TCSLogWithMark("caught error: \(error)")
self.error = error
} //do
} //for
return result
}

Expand Down
12 changes: 6 additions & 6 deletions xCreds.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1233,7 +1233,7 @@
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 5209;
CURRENT_PROJECT_VERSION = 5217;
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = UXP6YEHSPW;
FRAMEWORK_SEARCH_PATHS = (
Expand Down Expand Up @@ -1271,7 +1271,7 @@
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 5209;
CURRENT_PROJECT_VERSION = 5217;
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = UXP6YEHSPW;
FRAMEWORK_SEARCH_PATHS = (
Expand Down Expand Up @@ -1391,7 +1391,7 @@
CODE_SIGN_ENTITLEMENTS = "XCreds Login Overlay/XCreds_Login_Overlay.entitlements";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 5209;
CURRENT_PROJECT_VERSION = 5217;
DEVELOPMENT_TEAM = UXP6YEHSPW;
ENABLE_HARDENED_RUNTIME = YES;
FRAMEWORK_SEARCH_PATHS = (
Expand Down Expand Up @@ -1428,7 +1428,7 @@
CODE_SIGN_ENTITLEMENTS = "XCreds Login Overlay/XCreds_Login_Overlay.entitlements";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 5209;
CURRENT_PROJECT_VERSION = 5217;
DEVELOPMENT_TEAM = UXP6YEHSPW;
ENABLE_HARDENED_RUNTIME = YES;
FRAMEWORK_SEARCH_PATHS = (
Expand Down Expand Up @@ -1578,7 +1578,7 @@
CODE_SIGN_ENTITLEMENTS = XCreds/xCreds.entitlements;
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 5209;
CURRENT_PROJECT_VERSION = 5217;
DEVELOPMENT_TEAM = UXP6YEHSPW;
ENABLE_HARDENED_RUNTIME = YES;
FRAMEWORK_SEARCH_PATHS = (
Expand Down Expand Up @@ -1615,7 +1615,7 @@
CODE_SIGN_ENTITLEMENTS = XCreds/xCreds.entitlements;
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 5209;
CURRENT_PROJECT_VERSION = 5217;
DEVELOPMENT_TEAM = UXP6YEHSPW;
ENABLE_HARDENED_RUNTIME = YES;
FRAMEWORK_SEARCH_PATHS = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"repositoryURL": "https://github.com/apple/swift-argument-parser.git",
"state": {
"branch": null,
"revision": "fee6933f37fde9a5e12a1e4aeaa93fe60116ff2a",
"version": "1.2.2"
"revision": "8f4d2753f0e4778c76d5f05ad16c74f707390531",
"version": "1.2.3"
}
}
]
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@
filePath = "XCredsLoginPlugIn/Mechanisms/XCredsLoginMechanism.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "146"
endingLineNumber = "146"
startingLineNumber = "148"
endingLineNumber = "148"
landmarkName = "selectAndShowLoginWindow()"
landmarkType = "7">
</BreakpointContent>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<key>auth_mech_fixup.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>8</integer>
<integer>7</integer>
</dict>
<key>authrights.xcscheme_^#shared#^_</key>
<dict>
Expand All @@ -42,7 +42,7 @@
<key>test.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>7</integer>
<integer>8</integer>
</dict>
</dict>
<key>SuppressBuildableAutocreation</key>
Expand Down

0 comments on commit ca8e985

Please sign in to comment.