3333import java .security .Signature ;
3434import java .security .SignatureException ;
3535import java .util .Collection ;
36+ import java .util .Date ;
3637import java .util .Objects ;
3738
3839/**
@@ -58,6 +59,7 @@ private static class AppEngineCredentials extends GoogleCredentials
5859 private final String account ;
5960 private final Method getAccessToken ;
6061 private final Method getAccessTokenResult ;
62+ private final Method getExpirationTime ;
6163 private final Method signForApp ;
6264 private final Method getSignature ;
6365 private final Collection <String > scopes ;
@@ -74,6 +76,7 @@ private static class AppEngineCredentials extends GoogleCredentials
7476 "com.google.appengine.api.appidentity.AppIdentityService$GetAccessTokenResult" );
7577 this .getAccessTokenResult = serviceClass .getMethod ("getAccessToken" , Iterable .class );
7678 this .getAccessToken = tokenResultClass .getMethod ("getAccessToken" );
79+ this .getExpirationTime = tokenResultClass .getMethod ("getExpirationTime" );
7780 this .account = (String ) serviceClass .getMethod ("getServiceAccountName" )
7881 .invoke (appIdentityService );
7982 this .signForApp = serviceClass .getMethod ("signForApp" , byte [].class );
@@ -90,6 +93,7 @@ private static class AppEngineCredentials extends GoogleCredentials
9093 this .appIdentityService = unscoped .appIdentityService ;
9194 this .getAccessToken = unscoped .getAccessToken ;
9295 this .getAccessTokenResult = unscoped .getAccessTokenResult ;
96+ this .getExpirationTime = unscoped .getExpirationTime ;
9397 this .account = unscoped .account ;
9498 this .signForApp = unscoped .signForApp ;
9599 this .getSignature = unscoped .getSignature ;
@@ -107,7 +111,8 @@ public AccessToken refreshAccessToken() throws IOException {
107111 try {
108112 Object accessTokenResult = getAccessTokenResult .invoke (appIdentityService , scopes );
109113 String accessToken = (String ) getAccessToken .invoke (accessTokenResult );
110- return new AccessToken (accessToken , null );
114+ Date expirationTime = (Date ) getExpirationTime .invoke (accessTokenResult );
115+ return new AccessToken (accessToken , expirationTime );
111116 } catch (Exception e ) {
112117 throw new IOException ("Could not get the access token." , e );
113118 }
@@ -131,7 +136,7 @@ public String account() {
131136 @ Override
132137 public byte [] sign (byte [] toSign ) {
133138 try {
134- Object signingResult = signForApp .invoke (appIdentityService , ( Object ) toSign );
139+ Object signingResult = signForApp .invoke (appIdentityService , toSign );
135140 return (byte []) getSignature .invoke (signingResult );
136141 } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ex ) {
137142 throw new SigningException ("Failed to sign the provided bytes" , ex );
0 commit comments