Reputation: 1067
I am trying to get the Access Token using google oauth 2.0 but whenever i login again it goes through the consent screen process and generates a new token.
This is how i am getting the access token.
Uri.https("accounts.google.com", '/o/oauth2/auth', {
'response_type': 'code',
'client_id': identifier,
'redirect_uri': '$REDIRECTURL',
'scope': 'https://www.googleapis.com/auth/youtube.readonly',
});
then:
response = await http.post("https://oauth2.googleapis.com/token", body: {
'client_id': identifier,
'redirect_uri': '$REDIRECTURL',
'grant_type': 'authorization_code',
'code': code,
});
Upvotes: 1
Views: 90
Reputation: 2479
There are parameters setApprovalPrompt = auto / force
Force will cause that it will ask access scopes every time.
Auto won't ask, but you will not get "refresh_token" if you already received it before, and you only get "access_token" that is valid for 1 hour
Upvotes: 1
Reputation: 33441
I'm afraid that's how tokens work: whenever you ask one, you get a fresh one. Just store the access and refresh token (needed to refresh the access token when it expires) on your side and don't initiate the OAuth if it's not needed.
Upvotes: 1