33
33
import java .security .Signature ;
34
34
import java .security .SignatureException ;
35
35
import java .util .Collection ;
36
+ import java .util .Date ;
36
37
import java .util .Objects ;
37
38
38
39
/**
@@ -58,6 +59,7 @@ private static class AppEngineCredentials extends GoogleCredentials
58
59
private final String account ;
59
60
private final Method getAccessToken ;
60
61
private final Method getAccessTokenResult ;
62
+ private final Method getExpirationTime ;
61
63
private final Method signForApp ;
62
64
private final Method getSignature ;
63
65
private final Collection <String > scopes ;
@@ -74,6 +76,7 @@ private static class AppEngineCredentials extends GoogleCredentials
74
76
"com.google.appengine.api.appidentity.AppIdentityService$GetAccessTokenResult" );
75
77
this .getAccessTokenResult = serviceClass .getMethod ("getAccessToken" , Iterable .class );
76
78
this .getAccessToken = tokenResultClass .getMethod ("getAccessToken" );
79
+ this .getExpirationTime = tokenResultClass .getMethod ("getExpirationTime" );
77
80
this .account = (String ) serviceClass .getMethod ("getServiceAccountName" )
78
81
.invoke (appIdentityService );
79
82
this .signForApp = serviceClass .getMethod ("signForApp" , byte [].class );
@@ -90,6 +93,7 @@ private static class AppEngineCredentials extends GoogleCredentials
90
93
this .appIdentityService = unscoped .appIdentityService ;
91
94
this .getAccessToken = unscoped .getAccessToken ;
92
95
this .getAccessTokenResult = unscoped .getAccessTokenResult ;
96
+ this .getExpirationTime = unscoped .getExpirationTime ;
93
97
this .account = unscoped .account ;
94
98
this .signForApp = unscoped .signForApp ;
95
99
this .getSignature = unscoped .getSignature ;
@@ -107,7 +111,8 @@ public AccessToken refreshAccessToken() throws IOException {
107
111
try {
108
112
Object accessTokenResult = getAccessTokenResult .invoke (appIdentityService , scopes );
109
113
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 );
111
116
} catch (Exception e ) {
112
117
throw new IOException ("Could not get the access token." , e );
113
118
}
@@ -131,7 +136,7 @@ public String account() {
131
136
@ Override
132
137
public byte [] sign (byte [] toSign ) {
133
138
try {
134
- Object signingResult = signForApp .invoke (appIdentityService , ( Object ) toSign );
139
+ Object signingResult = signForApp .invoke (appIdentityService , toSign );
135
140
return (byte []) getSignature .invoke (signingResult );
136
141
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ex ) {
137
142
throw new SigningException ("Failed to sign the provided bytes" , ex );
0 commit comments