omarryhan/aiogoogle

Feature request: Callback when user credentials has been refreshed

Closed this issue · 2 comments

When user credentials is refreshed, I want to have them stored in a file so they can be re-read in to the application when restarting. Currently I'm explicitly calling a function before doing any work to refresh the credentials and store them but it would be nice if there was a callback parameter that could be used for performing actions when credentials been refreshed.

For reference, this is what I'm executing:

    async def refresh_user_creds(self, aiogoogle: Aiogoogle):
        updated, user_credentials = await aiogoogle.oauth2.refresh(
            user_creds=self.user_creds, client_creds=self.client_creds
        )
        if updated:
            self.user_creds = user_credentials
            aiogoogle.user_creds = user_credentials
            with self.user_creds_path.open("w") as f:
                yaml.safe_dump(dict(self.user_creds), f)

Hi! Is there a specific reason why you are manually refreshing everytime?

Normally, you just need the refresh_token which doesn’t change. If you store the entire user_creds object the first time you get it and don’t re save it ever again, it should theoretically last you indefinitely (Or until access is revoked)

you also don’t need to call refresh yourself. Just passing the user_creds as you first got it should be enough.

Hi! Is there a specific reason why you are manually refreshing everytime?

Normally, you just need the refresh_token which doesn’t change. If you store the entire user_creds object the first time you get it and don’t re save it ever again, it should theoretically last you indefinitely (Or until access is revoked)

you also don’t need to call refresh yourself. Just passing the user_creds as you first got it should be enough.

Ah; I was so sure that the refresh token would be changed every time you had used it I didn't even attempt to check if that was the case.

I'll close this one, thanks for the reply :)