Thanks for stopping by to let us know something could be better!
PLEASE READ: If you have a support contract with Google, please create an issue in the support console instead of filing on GitHub. This will ensure a timely response.
Is your feature request related to a problem? Please describe.
When having a long running code, the access token will expire and will not be automatically refreshed.
Describe the solution you'd like
withToken method should check if the token expire, and if so, try to refresh it using exchange instead of always returning the token.
Describe alternatives you've considered
I have a working solution that looks like that:
private var compute: Compute {
get async throws {
if let tokenProvider = tokenProvider {
let token: Token = try await withCheckedThrowingContinuation{ continuation in
do {
try tokenProvider.withToken{ token, error in
if let token = token {
continuation.resume(returning: token)
} else if let error = error {
continuation.resume(throwing: error)
}
}
} catch{
continuation.resume(throwing: error)
}
}
if let creationTime = self.tokenCreationTime, let expiresIn = token.ExpiresIn {
let expirationDate = creationTime.advanced(by: Double(expiresIn * 60))
print(expirationDate)
print(Date().advanced(by: -(5 * 60)))
if (expirationDate > Date().advanced(by: -(5 * 60))) {
self.tokenProvider = try self.tokenProviderFactory()
self.tokenCreationTime = Date()
}
}
return Compute(tokenProvider: tokenProvider)
} else {
let tokenProvider = try self.tokenProviderFactory()
self.tokenProvider = tokenProvider
self.tokenCreationTime = Date()
return Compute(tokenProvider: tokenProvider)
}
}
}
But I think this is better suited in the library itself as this is a common problem...
Thanks for stopping by to let us know something could be better!
PLEASE READ: If you have a support contract with Google, please create an issue in the support console instead of filing on GitHub. This will ensure a timely response.
Is your feature request related to a problem? Please describe.
When having a long running code, the access token will expire and will not be automatically refreshed.
Describe the solution you'd like
withTokenmethod should check if the token expire, and if so, try to refresh it usingexchangeinstead of always returning the token.Describe alternatives you've considered
I have a working solution that looks like that:
But I think this is better suited in the library itself as this is a common problem...