0

in my C# application, I am trying to get aouth2 access and refresh tokens:

https://developers.google.com/accounts/docs/OAuth2InstalledApp

On the phase: Handling the Response, When I make the call I am supposed to get something like:

{
  "access_token":"1/fFAGRNJru1FTz70BzhT3Zg",
  "expires_in":3920,
  "token_type":"Bearer",
  "refresh_token":"1/xEoDL4iW3cxlI7yDbSRFYNG01kVKM2C-259HOF2aQbI"
}

but I get

{
  "access_token":"1/fFAGRNJru1FTz70BzhT3Zg",
  "expires_in":3920,
  "token_type":"Bearer",
}

Thus: refresh_token is missing. I debugged and I am sure I hit the api method: FetchAccessAndRefreshTokens but I have no refresh_token.

PS: I am using 201306 API

Any ideas?

daghan
  • 948
  • 10
  • 18
  • seems same issue as: http://stackoverflow.com/questions/8433990/when-authenticating-with-oauth-and-youtube-always-get-error-invalid-grant-on – daghan Aug 27 '13 at 13:40
  • please see the answer by mariuss: http://stackoverflow.com/questions/18317623/no-refresh-token-permission-to-access-data-while-offline-google-oauth/18342063#18342063 – mengcheng Aug 27 '13 at 16:57

1 Answers1

1

In the API, within OAuth2ProviderForApplications.cs file, in GetAuthorizationUrl() method, on line 100 if you add &approval_prompt=force to the string:

return string.Format("{0}?scope={1}&state={2}&redirect_uri={3}&response_type={4}&" + "client_id={5}&access_type={6}&approval_prompt=force"

it works. But this is a horrible workaround plus it might create apache license issues.

How found: in google oauth2 playground (https://developers.google.com/oauthplayground/) this parameter (approval_prompt=force) is set and if you omit it, it does not give refresh token.

daghan
  • 948
  • 10
  • 18