Skip to content

Instantly share code, notes, and snippets.

@ChristianOConnor
Created January 13, 2023 10:31
Show Gist options
  • Save ChristianOConnor/ef1d487bb0b3d936f27428157f97cb11 to your computer and use it in GitHub Desktop.
Save ChristianOConnor/ef1d487bb0b3d936f27428157f97cb11 to your computer and use it in GitHub Desktop.
GCP IAMCredentialsClient Example 1
// Imports the Google Cloud client library
const {IAMCredentialsClient} = require('@google-cloud/iam-credentials');
// TODO(developer): replace with your prefered project values.
// The service account must be granted the roles/iam.serviceAccountTokenCreator role
const serviceAccount = '<SERVICE ACCOUNT NAME HERE>@<PROJECT NAME HERE>.iam.gserviceaccount.com'
const scopes = 'https://www.googleapis.com/auth/cloud-platform'
// Creates a client
const client = new IAMCredentialsClient();
async function generateAccessToken() {
const [token] = await client.generateAccessToken({
name: `projects/-/serviceAccounts/${serviceAccount}`,
scope: [scopes],
});
console.info(token);
}
generateAccessToken();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment