Created
January 13, 2023 10:31
-
-
Save ChristianOConnor/ef1d487bb0b3d936f27428157f97cb11 to your computer and use it in GitHub Desktop.
GCP IAMCredentialsClient Example 1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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