Google Diaglogflow - Authentication using service account key

Hi Folks,

I started working on building a custom chatbot on a wappler page. I developed the project on Google’s dialogflow. And I need to make a ‘detect intent’ API call from my website to Google Cloud Platform. Reference: https://cloud.google.com/dialogflow/docs/quick/api#detect_intent

I created an API action in Wappler and followed the instructions pertaining to the url, method and data. However, all of Dialogflow documentation suggests using a JSON key file for authentication. I extracted the key file from GCP successfully using the instructions at https://dialogflow.com/docs/reference/v2-auth-setup

However, I am unable to figure out how I can actually pass the file for authentication through Wappler. The Oauth actions only allow username or client ID/secret methods to authenticate. However, given that I am not trying to access user data but only the project data, it looks like I cannot use those methods. I found this link which clarified that aspect: https://cloud.google.com/docs/authentication/

Can someone help me understand how to authenticate the API action?
FYI - I tried passing the ‘Bearer key’ as an authorization header but that didn’t work. I created an Oauth2.0 client key from Google Cloud and created an Oauth2 server action in wappler but that didn’t work either. I think there needs to be a way to pass that file. Other folks building custom chatbots wrote a few lines in PHP to pass that file. Eg.:
$client = new \Google_Client();
$client->useApplicationDefaultCredentials();
$client->setScopes([‘https://www.googleapis.com/auth/dialogflow’]);
$client->setAuthConfig($secretFile);
$httpClient = $client->authorize();

Here’s another example where somebody implemented it through PHP code:

It looks like the person was able to just pass credentials (client email and private key) and was able to authenticate. I have both those values from the JSON key I downloaded. How can I pass those as credentials? Can I pass them as parameters?

I checked the docs and it seems that it requires a google service account for authentication. And that uses JSON Web Token for authentication. We currently have no oauth flow with JSON Web Token, I had a test with it once, will see if I can find that.

Thanks Patrick - let me know what you find. I am going to create a separate php file and copy over their example code to make the API call for now. It would be great if I could use Wappler’s API action for it but will look forward to it in future versions!

Hey @patrick I don’t suppose this is something that is in the works or being developed? :slight_smile:

Just hopefully asking while I try to manually implement this to make use of the Google BigQuery API that really needs the service account method of authentication.

Will see if @patrick can pick up the JWT flow used for Server Accounts.

1 Like

JWT signing was implemented in Wappler 3.4.2

This topic was automatically closed after 28 hours. New replies are no longer allowed.