Skip to content

Instantly share code, notes, and snippets.

@weikangchia
Last active July 20, 2022 11:06
Show Gist options
  • Save weikangchia/d5bb0aa1466407c86692ba00d8f16332 to your computer and use it in GitHub Desktop.
Save weikangchia/d5bb0aa1466407c86692ba00d8f16332 to your computer and use it in GitHub Desktop.
Generate DialogFlow V2 Access Token
const googleAuth = require('google-oauth-jwt');
function generateAccessToken() {
 return new Promise((resolve) => {
  googleAuth.authenticate(
   {
    email: <client_email>,
    key: <private_key>,
    scopes: 'https://www.googleapis.com/auth/cloud-platform',
   },
   (err, token) => {
    resolve(token);
   },
  );
 });
}
@weikangchia
Copy link
Author

If you want to generate the DialogFlow V2 access token through the "vanilla" way, you have come to the right place. In the above code, we will be using a nodejs package called, google-oauth-jwt, to help us generate the DialogFlow V2 access token.

You may find your client_email and private_key from the JSON key file you have downloaded from your Google Cloud Platform project's service account page. If you are unsure how/where to download it, you may checkout my blog post here.

To find out which scope which scope you may need, you may checkout the DialogFlow V2 REST API documentation page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment