TF-2384 Handle refresh token when token expired in NSE
Signed-off-by: dab246 <tdvu@linagora.com> (cherry picked from commit c8a39bb42792770c001ac90d6301d53126225d95)
This commit is contained in:
@@ -48,4 +48,13 @@ class KeychainController: KeychainControllerDelegate {
|
||||
}
|
||||
} catch {}
|
||||
}
|
||||
|
||||
func updateTokenOidc(accountId: String, newTokenOidc: TokenOidc) {
|
||||
do {
|
||||
if let sharingSession = retrieveSharingSessionFromKeychain(accountId: accountId) {
|
||||
let newSharingSession = sharingSession.updateTokenOidc(newTokenOidc: newTokenOidc)
|
||||
try keychain.set(newSharingSession.toJson() ?? "", key: accountId)
|
||||
}
|
||||
} catch {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,8 @@ struct KeychainSharingSession: Codable {
|
||||
let emailState: String?
|
||||
let tokenOIDC: TokenOidc?
|
||||
let basicAuth: String?
|
||||
let tokenEndpoint: String?
|
||||
let oidcScopes: [String]?
|
||||
}
|
||||
|
||||
extension KeychainSharingSession {
|
||||
@@ -19,7 +21,28 @@ extension KeychainSharingSession {
|
||||
apiUrl: self.apiUrl,
|
||||
emailState: newState,
|
||||
tokenOIDC: self.tokenOIDC,
|
||||
basicAuth: self.basicAuth
|
||||
basicAuth: self.basicAuth,
|
||||
tokenEndpoint: self.tokenEndpoint,
|
||||
oidcScopes: self.oidcScopes
|
||||
)
|
||||
}
|
||||
|
||||
func updateTokenOidc(newTokenOidc: TokenOidc) -> KeychainSharingSession {
|
||||
return KeychainSharingSession(
|
||||
accountId: self.accountId,
|
||||
userName: self.userName,
|
||||
authenticationType: self.authenticationType,
|
||||
apiUrl: self.apiUrl,
|
||||
emailState: self.emailState,
|
||||
tokenOIDC: TokenOidc(
|
||||
token: newTokenOidc.token,
|
||||
tokenId: newTokenOidc.tokenId,
|
||||
expiredTime: newTokenOidc.expiredTime,
|
||||
refreshToken: newTokenOidc.refreshToken
|
||||
),
|
||||
basicAuth: self.basicAuth,
|
||||
tokenEndpoint: self.tokenEndpoint,
|
||||
oidcScopes: self.oidcScopes
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -61,6 +61,8 @@ class NotificationService: UNNotificationServiceExtension {
|
||||
authenticationType: keychainSharingSession.authenticationType,
|
||||
tokenOidc: keychainSharingSession.tokenOIDC,
|
||||
basicAuth: keychainSharingSession.basicAuth,
|
||||
tokenEndpointUrl: keychainSharingSession.tokenEndpoint,
|
||||
oidcScopes: keychainSharingSession.oidcScopes,
|
||||
onSuccess: { emails in
|
||||
self.keychainController.updateEmailStateToKeychain(accountId: keychainSharingSession.accountId, newState: newEmailState)
|
||||
|
||||
@@ -90,7 +92,7 @@ class NotificationService: UNNotificationServiceExtension {
|
||||
}
|
||||
},
|
||||
onFailure: { error in
|
||||
self.modifiedContent?.body = newEmailDefaultMessage
|
||||
self.modifiedContent?.body = self.newEmailDefaultMessage
|
||||
self.modifiedContent?.badge = NSNumber(value: 1)
|
||||
return self.notify()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user