Derek
Derek

Reputation: 85

How to set up OAuth for managing Dialogflow user entities

I have a Dialogflow fulfillment written in PHP. It was using v1 of the Dialogflow API and I'm migrating to v2.

I don't need users to authenticate when using the app, but I used User Entities in v1 and under v2 these require authentication using OAuth.

I'm working through the documentation here and having trouble with Step 1: Configure the client object.

Since I am halfway through executing PHP code in order to fulfill a request from the user, how should I set $client->setRedirectUri? I need to get authorisation for the next line of code to then make a call via the Dialogflow projects.agent.sessions.entityTypes.patch API call so not sure where I would be 'redirecting' when the authorisation response comes back.

Upvotes: 1

Views: 551

Answers (2)

Gonzalo Molina
Gonzalo Molina

Reputation: 71

I had the same problem using Dialogflow library on NodeJs, here is what I did to solve the problem:

  • Go to 'Settings' of the chatbot in Dialogflow.
  • On General page, click on the link of Service Account (it redirects you to the Cloud Service Accounts).
  • Add a new credential, with a name (you can type what you want). In permissions, search Dialogflow API Client and mark the option of JSON credential.
    • Accept and a JSON file will be downloaded.
    • Add the route of that file to your server in a .env variable with the name GOOGLE_APPLICATION_CREDENTIALS.

And thats all!

Upvotes: 2

Prisoner
Prisoner

Reputation: 50701

The authorization required here isn't authorization from the user to set a Session Entity - it is authorization of your server to make sure it is allowed to access the API at all. You will typically do this with a service account and keep the auth info tightly controlled. This is similar to the "API keys" that were used with V1, but is using a more standard auth method.

Upvotes: 1

Related Questions