Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Providing a RefreshToken for the AccessTokenAuthenticator #203

Open
JasterV opened this issue May 8, 2023 · 1 comment
Open

Providing a RefreshToken for the AccessTokenAuthenticator #203

JasterV opened this issue May 8, 2023 · 1 comment

Comments

@JasterV
Copy link

JasterV commented May 8, 2023

Hi!

I have the following use case:

I generate manually both the token and access token to access the Gmail API.
Therefore, I want to use the AccessTokenAuthenticator, but I see it only accepts an access_token string, then I understand that there is no internal logic that will refresh the token automatically once the token expires:(

Is there a way I can take advantage of the refresh token that I have so the token gets internally refreshed?

Here is my code

        let authenticator = oauth2::authenticator::AccessTokenAuthenticator::builder(
            // It would be nice to pass the refresh token in here
            self.access_token.token().to_owned(),
        )
        .build()
        .await
        .map_err(AuthError::AuthenticatorBuilderError)?;

        let mut hub = Gmail::new(
            hyper::Client::builder().build(
                hyper_rustls::HttpsConnectorBuilder::new()
                    .with_native_roots()
                    .https_or_http()
                    .enable_http1()
                    .enable_http2()
                    .build(),
            ),
            authenticator,
        );
@JasterV
Copy link
Author

JasterV commented May 8, 2023

It would be also nice to be able to read the tokens directly from a file and do something like

// Get an ApplicationSecret instance by some means. It contains the `client_id` and 
// `client_secret`, among other things.
let token_info: TokenInfo = oauth2::read_token_from("/path/to/file");

  let authenticator = oauth2::authenticator::AccessTokenAuthenticator::builder(
            token_info
        )
        .persist_tokens_on_disk("path/to/file")
        .build()
        .await
        .map_err(AuthError::AuthenticatorBuilderError)?;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant