We are managing the user's Google calendar using google calendar APIs in the server. So we are getting the user's Google access token using the flutter google_sign_in library.
_googleSignIn.signIn().then((result) {
result!.authentication.then((googleKey) {
print(googleKey.accessToken);
print(googleKey.idToken);
})
})
It returns accessToken and idToken. But this access token will expire in 1 hour. We need this access token in our server to manage the user's calendar.
So we need a refresh token to get a new access token once it expires.
But there is no solution found to get a refresh token from the google_sign_in library.
Related discussions
(1) There is one approach to silent login every time the user is opening the application, but it is not feasible in our use case. Because we will have some scheduled calendar action in the server and we cannot expect the user to open the app every hour.
(2) This google doc Using OAuth 2.0 to Access Google APIs mentions that by using a refresh token we can get a new access token. But from the flutter app, we could not find any ways to get a refresh token.
(3) Some GitHub issues like this have some discussions, but nothing seems to be useful in getting the refresh token from a flutter app.
So it will be great If someone suggests a way to get a refresh token from a flutter app or any other possible workarounds for this situation.