2

I'm currently creating a Glassware application that is Java based and hosted on Google App Engine. Everything is going great... except for some reason AuthUtil stops being able to find the Credentials object for a user who submits a POST request.

When the user first navigates to my application's home page and signs in/authenticates with their Google Account everything works perfectly. The first card is posted to their timeline and the server responds appropriately to all incoming POSTS. But if the server sits idle for about 15-20 minutes then all POST requests begin failing.

After some debugging I found that AuthUtil.getCredential is no longer returning the user's Credential object after sitting idle for a short amount of time. The only way to correct this is to force the user to go back to my home page and re-sign in/authenticate.

Here is a snippet of the code that my application's servlet is using in "doPost":

Notification notification = jsonFactory.fromString(notiString, Notification.class);
String userId = notification.getUserToken();
LOG.info("SERVLET - Request contained user token: " + userId);
Credentials currUser = AuthUtil.getCredential(userId);
if (currUser != null)
{
    LOG.info("SERVLET - User found");
}
else
{
    LOG.severe("SERVLET - User NOT FOUND");
}

NOTE: I can confirm that all incoming POSTs include the user's token identifier string.

ErstwhileIII
  • 4,829
  • 2
  • 23
  • 37
  • 1
    AuthUtil is a utility class included in the sample code. Feel free to dig into it to troubleshoot this issue. Here are the first things I'd look into: Is the userId that you're getting in the notification reasonable? Go to the App Engine admin console and inspect the data store. Do you see records that match that user ID? If not, some other code may be corrupting / purging them – mimming Oct 08 '13 at 19:37
  • @JennyMurphy thanks for the response. The user IDs that I'm receiving are 21 characters long and numeric only. Would these be considered reasonable? Secondly, I've attempted to look into AuthUtil. The only code in `AuthUtil.getCredential(String userId)` is `AuthUtil.newAuthorizationCodeFlow().loadCredential(userId)`. I can't debug any deeper then this because AuthorizationCodeFlow is a private class from the oath client jar that I can't step through. – kurib0sShoe Oct 13 '13 at 03:36
  • @JennyMurphy to further clarify… my data store contains a record with a matching user id in a table that I defined. When I'm manually examining the data I can find the record related to the user that sent the notification but I wouldn't be able to post any timeline updates since `AuthUtil.getCredential(String userId)` is failing to return a Credential object. – kurib0sShoe Oct 13 '13 at 03:39
  • Numeric IDs make sense. The loadCredential method is indirectly calling the load method on your CredentialStore. The quick start ships with one that uses a memory credential store: https://github.com/googleglass/mirror-quickstart-java/blob/master/src/main/java/com/google/glassware/ListableMemoryCredentialStore.java If you're on app engine you'll want to use a different implementation like the AppEngineCredentialStore shipped with the Java Google API client library. – mimming Oct 16 '13 at 23:12

0 Answers0