File tree Expand file tree Collapse file tree
javatests/com/google/auth/appengine
java/com/google/auth/appengine Expand file tree Collapse file tree Original file line number Diff line number Diff line change 3535import com .google .auth .oauth2 .GoogleCredentials ;
3636import com .google .common .collect .ImmutableList ;
3737import com .google .appengine .api .appidentity .AppIdentityService ;
38+ import com .google .appengine .api .appidentity .AppIdentityService .GetAccessTokenResult ;
3839import com .google .appengine .api .appidentity .AppIdentityServiceFactory ;
3940
4041import java .io .IOException ;
4142import java .util .Collection ;
43+ import java .util .Date ;
4244
4345/**
4446 * OAuth2 credentials representing the built-in service account for Google App ENgine.
@@ -72,8 +74,10 @@ public AccessToken refreshAccessToken() throws IOException {
7274 if (createScopedRequired ()) {
7375 throw new IOException ("AppEngineCredentials requires createScoped call before use." );
7476 }
75- String accessToken = appIdentityService .getAccessToken (scopes ).getAccessToken ();
76- return new AccessToken (accessToken , null );
77+ GetAccessTokenResult accessTokenResponse = appIdentityService .getAccessToken (scopes );
78+ String accessToken = accessTokenResponse .getAccessToken ();
79+ Date expirationTime = accessTokenResponse .getExpirationTime ();
80+ return new AccessToken (accessToken , expirationTime );
7781 }
7882
7983 @ Override
Original file line number Diff line number Diff line change 3838import static org .junit .Assert .assertNotSame ;
3939
4040import com .google .auth .Credentials ;
41+ import com .google .auth .oauth2 .AccessToken ;
4142import com .google .auth .oauth2 .GoogleCredentials ;
4243
4344import org .junit .Test ;
4950import java .util .Arrays ;
5051import java .util .Collection ;
5152import java .util .Collections ;
53+ import java .util .Date ;
5254import java .util .List ;
5355import java .util .Map ;
5456
@@ -76,6 +78,19 @@ public void constructor_usesAppIdentityService() throws IOException {
7678 assertContainsBearerToken (metadata , expectedAccessToken );
7779 }
7880
81+ @ Test
82+ public void refreshAccessToken_sameAs () throws IOException {
83+ final String expectedAccessToken = "ExpectedAccessToken" ;
84+
85+ MockAppIdentityService appIdentity = new MockAppIdentityService ();
86+ appIdentity .setAccessTokenText (expectedAccessToken );
87+ appIdentity .setExpiration (new Date (System .currentTimeMillis () + 60L * 60L * 100L ));
88+ AppEngineCredentials credentials = new AppEngineCredentials (SCOPES , appIdentity );
89+ AccessToken accessToken = credentials .refreshAccessToken ();
90+ assertEquals (appIdentity .getAccessTokenText (), accessToken .getTokenValue ());
91+ assertEquals (appIdentity .getExpiration (), accessToken .getExpirationTime ());
92+ }
93+
7994 @ Test
8095 public void createScoped_clonesWithScopes () throws IOException {
8196 final String expectedAccessToken = "ExpectedAccessToken" ;
Original file line number Diff line number Diff line change 3636import com .google .appengine .api .appidentity .PublicCertificate ;
3737
3838import java .util .Collection ;
39+ import java .util .Date ;
3940
4041/**
4142 * Mock implementation of AppIdentityService interface for testing.
@@ -44,6 +45,7 @@ public class MockAppIdentityService implements AppIdentityService {
4445
4546 private int getAccessTokenCallCount = 0 ;
4647 private String accessTokenText = null ;
48+ private Date expiration = null ;
4749
4850 public MockAppIdentityService () {
4951 }
@@ -60,6 +62,14 @@ public void setAccessTokenText(String text) {
6062 accessTokenText = text ;
6163 }
6264
65+ public Date getExpiration () {
66+ return expiration ;
67+ }
68+
69+ public void setExpiration (Date expiration ) {
70+ this .expiration = expiration ;
71+ }
72+
6373 @ Override
6474 public SigningResult signForApp (byte [] signBlob ) {
6575 return null ;
@@ -82,7 +92,7 @@ public GetAccessTokenResult getAccessToken(Iterable<String> scopes) {
8292 if (scopeCount == 0 ) {
8393 throw new AppIdentityServiceFailureException ("No scopes specified." );
8494 }
85- return new GetAccessTokenResult (accessTokenText , null );
95+ return new GetAccessTokenResult (accessTokenText , expiration );
8696 }
8797
8898 @ Override
You can’t perform that action at this time.
0 commit comments