@@ -46,7 +46,6 @@ private static class AppEngineCredentials extends GoogleCredentials {
4646 private final Method getAccessToken ;
4747 private final Method getAccessTokenResult ;
4848 private final Collection <String > scopes ;
49- private final boolean scopesRequired ;
5049
5150 AppEngineCredentials () {
5251 try {
@@ -61,19 +60,16 @@ private static class AppEngineCredentials extends GoogleCredentials {
6160 this .getAccessTokenResult = serviceClass .getMethod ("getAccessToken" , Iterable .class );
6261 this .getAccessToken = tokenResultClass .getMethod ("getAccessToken" );
6362 this .scopes = null ;
64- this .scopesRequired = true ;
6563 } catch (Exception e ) {
66- throw new RuntimeException ("Could not create AppEngineCredentials using reflection." );
64+ throw new RuntimeException ("Could not create AppEngineCredentials." , e );
6765 }
6866 }
6967
70- AppEngineCredentials (Collection <String > scopes , Object appIdentityService ,
71- Method getAccessToken , Method getAccessTokenResult ) {
72- this .appIdentityService = appIdentityService ;
73- this .getAccessToken = getAccessToken ;
74- this .getAccessTokenResult = getAccessTokenResult ;
68+ AppEngineCredentials (Collection <String > scopes , AppEngineCredentials unscoped ) {
69+ this .appIdentityService = unscoped .appIdentityService ;
70+ this .getAccessToken = unscoped .getAccessToken ;
71+ this .getAccessTokenResult = unscoped .getAccessTokenResult ;
7572 this .scopes = scopes ;
76- this .scopesRequired = (scopes == null || scopes .isEmpty ());
7773 }
7874
7975 /**
@@ -89,19 +85,18 @@ public AccessToken refreshAccessToken() throws IOException {
8985 String accessToken = (String ) getAccessToken .invoke (accessTokenResult );
9086 return new AccessToken (accessToken , null );
9187 } catch (Exception e ) {
92- throw new RuntimeException ("Could not get the access token using reflection." );
88+ throw new IOException ("Could not get the access token." , e );
9389 }
9490 }
9591
9692 @ Override
9793 public boolean createScopedRequired () {
98- return scopesRequired ;
94+ return scopes == null || scopes . isEmpty () ;
9995 }
10096
10197 @ Override
10298 public GoogleCredentials createScoped (Collection <String > scopes ) {
103- return new AppEngineCredentials (
104- scopes , appIdentityService , getAccessToken , getAccessTokenResult );
99+ return new AppEngineCredentials (scopes , this );
105100 }
106101 }
107102
@@ -308,6 +303,7 @@ public static ServiceAccountAuthCredentials createForJson(InputStream jsonCreden
308303 tempServiceAccountCredentials .getClientEmail (),
309304 tempServiceAccountCredentials .getPrivateKey ());
310305 }
311- throw new IOException ("The given JSON Credentials Stream is not a service account credential." );
306+ throw new IOException (
307+ "The given JSON Credentials Stream is not for a service account credential." );
312308 }
313309}
0 commit comments