Skip to content

Auto-refresh auth tokens. #11

@ruseinov

Description

@ruseinov

It might actually be beneficial to auto-refresh tokens by checking if they are close to expiration as having to spawn a separate thread for that seems laborious.

The current approach I've taken is as follows:

pub fn init_pubsub() -> cloud_pubsub::Client {
    ....

    let client = cloud_pubsub::Client::new_with_string(pubsub_credentials).unwrap();
    let refresh_client = client.clone();
    spawn(lazy(move |_ctx| {
        refresh_client.spawn_token_renew(GOOGLE_TOKEN_REFRESH_INTERVAL)
    }));
    client
}

But I can't imagine a scenario where one would not want to refresh token when it expires, nor do I think it's an implementation detail that the library user should care about.

What we could do is check token expiration on request and if it's close to be expired - spawn renew it right there and then.
It just has to be implemented in a performant way.

I do understand why the current approach has been taken: it makes the library easier to read and understand, but I'm sure we can come up with a solution that would work just as well without the extra burden on the user's side.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions