I have have bypassed the whole AuthorizationCodeInstalledApp authorize() method and created a new subclass which bypasses the jetty server implementation process.
The methods are as follows
- getAuthorizationFromStorage : Get access token from stored credentials.
- getAuthorizationFromGoogle : Get the authentication with the credentials from Google creates the url that will lead the user to the authentication page and creating a custom defined name-value pair in the state parameter. The value should be encoded with base64 encoder so we can receive the same code redirected from google after authentication.
saveAuthorizationFromGoogle : Save the credentials that we get from google.
- Create the GoogleAuthorizationCodeFlow object from the credentialDatastorfrom the response received from the google after authentication.
- Hit google to get the permanent refresh-token that can be used to get the accesstoken of the user any time .
- Store the tokens like accesstoken and refreshtoken in the filename as userid
Checkout the code Implementation here