Skip to content

Commit

Permalink
#1222 add minExpiryDuration to id tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
sosnovsky committed Dec 30, 2021
1 parent 587bd81 commit 80dd669
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions FlowCrypt/Functionality/Services/GoogleUserService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ struct IdToken: Codable {
}

extension IdToken {
var isExpired: Bool {
Double(exp) < Date().timeIntervalSince1970
var expiryDuration: Double {
Date(timeIntervalSince1970: Double(exp)).timeIntervalSinceNow
}
}

Expand Down Expand Up @@ -254,12 +254,12 @@ extension GoogleUserService {

// MARK: - Tokens
extension GoogleUserService {
func getCachedOrRefreshedIdToken() async throws -> String {
func getCachedOrRefreshedIdToken(minExpiryDuration: Double = 0) async throws -> String {
guard let idToken = idToken else { throw(IdTokenError.missingToken) }

let decodedToken = try decode(idToken: idToken)

guard !decodedToken.isExpired else {
guard decodedToken.expiryDuration > minExpiryDuration else {
let (_, updatedToken) = try await performTokenRefresh()
return updatedToken
}
Expand Down

0 comments on commit 80dd669

Please sign in to comment.