@@ -113,7 +113,7 @@ following are searched (in order) to find the Application Default Credentials:
113113
114114To get Credentials from a Service Account JSON key use ` GoogleCredentials.fromStream(InputStream) `
115115or ` GoogleCredentials.fromStream(InputStream, HttpTransportFactory) ` . Note that the credentials must
116- be refreshed before the access token is available.
116+ be refreshed before the access token is available.
117117
118118``` java
119119GoogleCredentials credentials = GoogleCredentials . fromStream(new FileInputStream (" /path/to/credentials.json" ));
@@ -123,6 +123,31 @@ AccessToken token = credentials.getAccessToken();
123123AccessToken token = credentials. refreshAccessToken();
124124```
125125
126+ ### ImpersonatedCredentials
127+
128+ Allows a credentials issued to a user or service account to
129+ impersonate another. The source project using ImpersonaedCredentials must enable the
130+ "IAMCredentials" API. Also, the target service account must grant the orginating principal
131+ the "Service Account Token Creator" IAM role.
132+
133+ ``` java
134+ String credPath = " /path/to/svc_account.json" ;
135+ ServiceAccountCredentials sourceCredentials = ServiceAccountCredentials
136+ .fromStream(new FileInputStream (credPath));
137+ sourceCredentials = (ServiceAccountCredentials ) sourceCredentials
138+ .createScoped(Arrays . asList(" https://www.googleapis.com/auth/iam" ));
139+
140+ ImpersonatedCredentials targetCredentials = ImpersonatedCredentials . create(sourceCredentials,
141+ 142+ Arrays . asList(" https://www.googleapis.com/auth/devstorage.read_only" ), 300 );
143+
144+ Storage storage_service = StorageOptions . newBuilder(). setProjectId(" project-id" )
145+ .setCredentials(targetCredentials). build(). getService();
146+
147+ for (Bucket b : storage_service. list(). iterateAll())
148+ System . out. println(b);
149+ ```
150+
126151## CI Status
127152
128153Java Version | Status
0 commit comments