Skip to content

Commit

Permalink
fixed issue with token update time
Browse files Browse the repository at this point in the history
  • Loading branch information
twocanoes committed Jun 8, 2023
1 parent af491f5 commit 0d14279
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 16 deletions.
14 changes: 8 additions & 6 deletions XCreds/ScheduleManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,23 @@ class ScheduleManager {
var nextCheckTime = Date()
var timer:Timer?
func setNextCheckTime() {
if let timer = timer, timer.isValid==true {
return
}
var rate = DefaultsOverride.standardOverride.integer(forKey: PrefKeys.refreshRateHours.rawValue)
var rate = DefaultsOverride.standardOverride.double(forKey: PrefKeys.refreshRateHours.rawValue)

if rate < 1 {
rate = 1
}
else if rate > 168 {
rate = 168
}
nextCheckTime = Date(timeIntervalSinceNow: TimeInterval(rate*60*60))
nextCheckTime = Date(timeIntervalSinceNow: rate*60*60)

}
func startCredentialCheck() {
if let timer = timer, timer.isValid==true {
return
}

setNextCheckTime()
nextCheckTime=Date()
timer=Timer.scheduledTimer(withTimeInterval: 60*5, repeats: true, block: { timer in //check every 5 minutes
self.checkToken()
})
Expand All @@ -55,6 +55,8 @@ class ScheduleManager {
return
}
setNextCheckTime()
TCSLogWithMark("Checking token now (\(Date())). Next token check will be at \(nextCheckTime)")

TokenManager.shared.getNewAccessToken(completion: { isSuccessful, hadConnectionError in

if hadConnectionError==true {
Expand Down
8 changes: 4 additions & 4 deletions XCreds/TokenManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class TokenManager {

if let accessToken = creds.accessToken, accessToken.count>0{
TCSLogWithMark("Saving Access Token")
if keychainUtil.updatePassword(serviceName: "xcreds",accountName:PrefKeys.accessToken.rawValue, pass: accessToken,shouldUpdateACL: setACL, keychainPassword:password) == false {
if keychainUtil.updatePassword(serviceName: "xcreds ".appending(PrefKeys.accessToken.rawValue),accountName:PrefKeys.accessToken.rawValue, pass: accessToken,shouldUpdateACL: setACL, keychainPassword:password) == false {
TCSLogErrorWithMark("Error Updating Access Token")

return false
Expand All @@ -83,7 +83,7 @@ class TokenManager {
}
if let idToken = creds.idToken, idToken.count>0{
TCSLogWithMark("Saving idToken Token")
if keychainUtil.updatePassword(serviceName: "xcreds",accountName:PrefKeys.idToken.rawValue, pass: idToken, shouldUpdateACL: setACL, keychainPassword:password) == false {
if keychainUtil.updatePassword(serviceName: "xcreds ".appending(PrefKeys.idToken.rawValue),accountName:PrefKeys.idToken.rawValue, pass: idToken, shouldUpdateACL: setACL, keychainPassword:password) == false {
TCSLogErrorWithMark("Error Updating idToken Token")

return false
Expand All @@ -94,7 +94,7 @@ class TokenManager {
if let refreshToken = creds.refreshToken, refreshToken.count>0 {
TCSLogWithMark("Saving refresh Token")

if keychainUtil.updatePassword(serviceName: "xcreds",accountName:PrefKeys.refreshToken.rawValue, pass: refreshToken,shouldUpdateACL: setACL, keychainPassword:password) == false {
if keychainUtil.updatePassword(serviceName: "xcreds ".appending(PrefKeys.refreshToken.rawValue),accountName:PrefKeys.refreshToken.rawValue, pass: refreshToken,shouldUpdateACL: setACL, keychainPassword:password) == false {
TCSLogErrorWithMark("Error Updating refreshToken Token")

return false
Expand Down Expand Up @@ -141,7 +141,7 @@ TCSLogWithMark()

let keychainUtil = KeychainUtil()
TCSLogWithMark()
let refreshAccountAndToken = try? keychainUtil.findPassword(serviceName: "xcreds",accountName:PrefKeys.refreshToken.rawValue)
let refreshAccountAndToken = try? keychainUtil.findPassword(serviceName: "xcreds ".appending(PrefKeys.refreshToken.rawValue),accountName:PrefKeys.refreshToken.rawValue)

let clientID = defaults.string(forKey: PrefKeys.clientID.rawValue)
let keychainAccountAndPassword = try? keychainUtil.findPassword(serviceName: "xcreds local password",accountName:PrefKeys.password.rawValue)
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 = 4144;
CURRENT_PROJECT_VERSION = 4153;
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = UXP6YEHSPW;
FRAMEWORK_SEARCH_PATHS = (
Expand Down Expand Up @@ -1270,7 +1270,7 @@
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 4144;
CURRENT_PROJECT_VERSION = 4153;
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = UXP6YEHSPW;
FRAMEWORK_SEARCH_PATHS = (
Expand Down Expand Up @@ -1389,7 +1389,7 @@
CODE_SIGN_ENTITLEMENTS = "XCreds Login Overlay/XCreds_Login_Overlay.entitlements";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 4144;
CURRENT_PROJECT_VERSION = 4153;
DEVELOPMENT_TEAM = UXP6YEHSPW;
ENABLE_HARDENED_RUNTIME = YES;
FRAMEWORK_SEARCH_PATHS = (
Expand Down Expand Up @@ -1425,7 +1425,7 @@
CODE_SIGN_ENTITLEMENTS = "XCreds Login Overlay/XCreds_Login_Overlay.entitlements";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 4144;
CURRENT_PROJECT_VERSION = 4153;
DEVELOPMENT_TEAM = UXP6YEHSPW;
ENABLE_HARDENED_RUNTIME = YES;
FRAMEWORK_SEARCH_PATHS = (
Expand Down Expand Up @@ -1574,7 +1574,7 @@
CODE_SIGN_ENTITLEMENTS = XCreds/xCreds.entitlements;
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 4144;
CURRENT_PROJECT_VERSION = 4153;
DEVELOPMENT_TEAM = UXP6YEHSPW;
ENABLE_HARDENED_RUNTIME = YES;
FRAMEWORK_SEARCH_PATHS = (
Expand Down Expand Up @@ -1610,7 +1610,7 @@
CODE_SIGN_ENTITLEMENTS = XCreds/xCreds.entitlements;
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 4144;
CURRENT_PROJECT_VERSION = 4153;
DEVELOPMENT_TEAM = UXP6YEHSPW;
ENABLE_HARDENED_RUNTIME = YES;
FRAMEWORK_SEARCH_PATHS = (
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,116 @@
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "F668A9FC-AF37-472C-9B8E-8E91096A7BE4"
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "XCreds/ScheduleManager.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "32"
endingLineNumber = "32"
landmarkName = "startCredentialCheck()"
landmarkType = "7">
<Locations>
<Location
uuid = "F668A9FC-AF37-472C-9B8E-8E91096A7BE4 - 1135ca0c82da3b58"
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
symbolName = "XCreds.ScheduleManager.startCredentialCheck() -&gt; ()"
moduleName = "XCreds"
usesParentBreakpointCondition = "Yes"
urlString = "file:///Users/tperfitt/Documents/Projects/xcreds/XCreds/ScheduleManager.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "32"
endingLineNumber = "32"
offsetFromSymbolStart = "100">
</Location>
<Location
uuid = "F668A9FC-AF37-472C-9B8E-8E91096A7BE4 - 1135ca0c82da3b58"
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
symbolName = "XCreds.ScheduleManager.startCredentialCheck() -&gt; ()"
moduleName = "XCreds"
usesParentBreakpointCondition = "Yes"
urlString = "file:///Users/tperfitt/Documents/Projects/xcreds/XCreds/ScheduleManager.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "32"
endingLineNumber = "32"
offsetFromSymbolStart = "232">
</Location>
</Locations>
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "97DAC11F-E3DF-4C68-9772-17CFCD7A08B1"
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "XCreds/ScheduleManager.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "16"
endingLineNumber = "16"
landmarkName = "setNextCheckTime()"
landmarkType = "7">
<Locations>
<Location
uuid = "97DAC11F-E3DF-4C68-9772-17CFCD7A08B1 - 7f6a61eb647fd95d"
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
symbolName = "XCreds.ScheduleManager.setNextCheckTime() -&gt; ()"
moduleName = "XCreds"
usesParentBreakpointCondition = "Yes"
urlString = "file:///Users/tperfitt/Documents/Projects/xcreds/XCreds/ScheduleManager.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "16"
endingLineNumber = "16"
offsetFromSymbolStart = "104">
</Location>
<Location
uuid = "97DAC11F-E3DF-4C68-9772-17CFCD7A08B1 - 7f6a61eb647fd95d"
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
symbolName = "XCreds.ScheduleManager.setNextCheckTime() -&gt; ()"
moduleName = "XCreds"
usesParentBreakpointCondition = "Yes"
urlString = "file:///Users/tperfitt/Documents/Projects/xcreds/XCreds/ScheduleManager.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "16"
endingLineNumber = "16"
offsetFromSymbolStart = "148">
</Location>
<Location
uuid = "97DAC11F-E3DF-4C68-9772-17CFCD7A08B1 - 7f6a61eb647fd95d"
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
symbolName = "XCreds.ScheduleManager.setNextCheckTime() -&gt; ()"
moduleName = "XCreds"
usesParentBreakpointCondition = "Yes"
urlString = "file:///Users/tperfitt/Documents/Projects/xcreds/XCreds/ScheduleManager.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "16"
endingLineNumber = "16"
offsetFromSymbolStart = "108">
</Location>
</Locations>
</BreakpointContent>
</BreakpointProxy>
</Breakpoints>
</Bucket>

0 comments on commit 0d14279

Please sign in to comment.