final Credential credential = new Credential.
Builder(BearerToken.authorizationHeaderAccessMethod()).build();
AppEngineCredentialStore appEngineCredentialStore =
new AppEngineCredentialStore();
if (! appEngineCredentialStore.load(stripesActionBeanContext.getUser().getUserId(), credential)) {
log.debug("calling AuthorizationCodeRequestUrl");
String url =
Constants.GOOGLE_API_KEY)
.setRedirectUri(Constants
.googleOJCCallbackUri(stripesActionBeanContext.getRequest().getScheme(),
stripesActionBeanContext.getRequest().getServerName(),
stripesActionBeanContext.getRequest().getServerPort()))
.setState(stripesActionBeanContext.getRequest().getRequestURI())
//.set("access_type", "offline")
.build();
log.debug("redirect url: {}", url);
return (new RedirectResolution(url));
}
My callback has this:
TokenResponse tokenResponse =
new AuthorizationCodeTokenRequest(new UrlFetchTransport(),
new JacksonFactory(),
this.code)
.setRedirectUri(Constants.googleOJCCallbackUri(
getContext().getRequest().getScheme(),
getContext().getRequest().getServerName(),
getContext().getRequest().getServerPort()))
.setClientAuthentication(
new ClientParametersAuthentication(
Constants.GOOGLE_API_KEY,
Constants.GOOGLE_API_SECRET))
.execute();
Credential credential2 = new Credential.Builder(BearerToken.authorizationHeaderAccessMethod())
.addRefreshListener(new CredentialStoreRefreshListener(getContext().getUser().getUserId(),
new AppEngineCredentialStore()))
.setJsonFactory(new JacksonFactory())
.setClientAuthentication(
new ClientParametersAuthentication(
Constants.GOOGLE_API_KEY,
Constants.GOOGLE_API_SECRET))
.setTransport(new UrlFetchTransport())
.build()
.setFromTokenResponse(tokenResponse);
if (! credential2.refreshToken()) {
this.addMessage("no refresh token");
}
AppEngineCredentialStore appEngineCredentialStore = new AppEngineCredentialStore();
appEngineCredentialStore.store(getContext().getUser().getUserId(), credential2);
This is how I use the Credential. When the token is expired this code fails.
HttpRequestFactory requestFactory = new UrlFetchTransport()
.createRequestFactory(getContext().getCredential());
HttpResponse httpResponse = requestFactory
.execute();
Thanks!