Ok, resolved. You have to add the parameter
approval_type=force
to the parameters.
Ok, resolved. You have to add the parameter
approval_type=force
to the parameters.
I believe that is only needed because the user has already granted permission to the app and so Google is just re-issuing the same response each time (without the refresh token, because it wasn't asked for the first time). You could've probably made it work by having the user revoke access to the app before trying to authorize again.
Having never authorized my sample app, I got it to work the first time, without approval_type=force. But again, that's just because I didn't already have a history of approval with Google.
Craig Walls
Spring Social Project Lead
By using Craig's suggestion to override GoogleOAuth2Template buildAuthorizeUrl I was able to get the refreshToken. I still have one minor problem. Once the refresh token is used, the refreshToken is changed to null by the framework; after calling connection.refresh(), the refreshToken value is wiped out and there is no way to manually update the Connection object with the old reusable refreshToken before calling connectionRepository.updateConnection(connection). I want to be able to update the connection in the userconnection table to retain the old refreshToken. Is there an easy way to populate the refreshToken field without having to write extra database code to do it? Preferably I would have liked to just call a public setter method on the Connection object.