1

I am using glcient-java library to handle Google oAuth Flow.As recommended in docs, i have two classes extending AbstractAuthorizationCodeServlet and AbstractAuthorizationCodeCallbackServlet respectively. The flow is going smooth. I am now trying to persist/store the Credential Object i receive in onSuccess method to the database. The situation is , the users(identified by a uniqueID) have the option to connect one or multiple google accounts. What i want is everytime a new Google Account is connected via oAuth Flow and from onSuccess Method, i should be able to add a row in database where uniqueID,GoogleAccountEmailID,AccessToken,RefreshToken are stored in the table.

Here are my important methods of Implementation:

@Override
protected AuthorizationCodeFlow initializeFlow() throws ServletException,
        IOException {
    return 
            new GoogleAuthorizationCodeFlow.Builder(
                    new NetHttpTransport(), JacksonFactory.getDefaultInstance(),Constants.GOOGLE_CLIENT_ID, Constants.GOOGLE_CLIENT_SECRET,Constants.SCOPES)
            .setAccessType("offline")
            .setApprovalPrompt("force")
            .build();
}

@Override
protected void onSuccess(HttpServletRequest req, HttpServletResponse resp,
        Credential credential) throws ServletException, IOException {

    // Creates a new Gmail API client.
    System.out.print("Successfully Authenticated");
    System.out.println("Access Token"+credential.getAccessToken());
    System.out.println("Ref Token"+credential.getRefreshToken());
    System.out.println("");


    /*Here i want to store the accessToken,RefreshToken,uniqueID,credentialEmailID*/



}

Also, How should i be implementing my getUserID() method to give me emailID extracted from oauth Token response or from Credential Object.

Please help.

zee
  • 502
  • 8
  • 28

0 Answers0