Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add expiration date to App Engine credentials #894

Merged
merged 1 commit into from
Apr 11, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import java.security.Signature;
import java.security.SignatureException;
import java.util.Collection;
import java.util.Date;
import java.util.Objects;

/**
Expand All @@ -58,6 +59,7 @@ private static class AppEngineCredentials extends GoogleCredentials
private final String account;
private final Method getAccessToken;
private final Method getAccessTokenResult;
private final Method getExpirationTime;
private final Method signForApp;
private final Method getSignature;
private final Collection<String> scopes;
Expand All @@ -74,6 +76,7 @@ private static class AppEngineCredentials extends GoogleCredentials
"com.google.appengine.api.appidentity.AppIdentityService$GetAccessTokenResult");
this.getAccessTokenResult = serviceClass.getMethod("getAccessToken", Iterable.class);
this.getAccessToken = tokenResultClass.getMethod("getAccessToken");
this.getExpirationTime = tokenResultClass.getMethod("getExpirationTime");
this.account = (String) serviceClass.getMethod("getServiceAccountName")
.invoke(appIdentityService);
this.signForApp = serviceClass.getMethod("signForApp", byte[].class);
Expand All @@ -90,6 +93,7 @@ private static class AppEngineCredentials extends GoogleCredentials
this.appIdentityService = unscoped.appIdentityService;
this.getAccessToken = unscoped.getAccessToken;
this.getAccessTokenResult = unscoped.getAccessTokenResult;
this.getExpirationTime = unscoped.getExpirationTime;
this.account = unscoped.account;
this.signForApp = unscoped.signForApp;
this.getSignature = unscoped.getSignature;
Expand All @@ -107,7 +111,8 @@ public AccessToken refreshAccessToken() throws IOException {
try {
Object accessTokenResult = getAccessTokenResult.invoke(appIdentityService, scopes);
String accessToken = (String) getAccessToken.invoke(accessTokenResult);
return new AccessToken(accessToken, null);
Date expirationTime = (Date) getExpirationTime.invoke(accessTokenResult);
return new AccessToken(accessToken, expirationTime);
} catch (Exception e) {
throw new IOException("Could not get the access token.", e);
}
Expand All @@ -131,7 +136,7 @@ public String account() {
@Override
public byte[] sign(byte[] toSign) {
try {
Object signingResult = signForApp.invoke(appIdentityService, (Object) toSign);
Object signingResult = signForApp.invoke(appIdentityService, toSign);

This comment was marked as spam.

return (byte[]) getSignature.invoke(signingResult);
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) {
throw new SigningException("Failed to sign the provided bytes", ex);
Expand Down