authenticationdialogflow-esgoogle-cloud-identity

What is the best way to pass credentials to and from Dialogflow


I might be missing this entirely in the documentation, but I'm looking for examples of passing authentication to and from Dialogflow.

The Dialogflow examples I find are open for all users, but I want the Dialogflow interaction to be logged into a specific authenticated user. I setup Google Cloud Identity and Firestore Auth, but I can not find good examples of how to move that authentication information securely through Dialogflow in its requests to the Firestore database. I am using NodeJS on the backend webhooks.


Solution

  • There's no straight-forward option to authenticate a user for Dialogflow fulfillment. A suggestion to handle how to pass credentials and the webhook connection is as follows:

    1. The end-user authenticates to your server
    2. The server creates a new session for this conversation in Dialogflow (or validates the current session)
    3. Your server uses the payload field in the QueryParameters object in the detectIntent request to pass the necessary information to validate the user during the fulfillment
    4. Configure mTLS for your webhook to create a secure connection
    5. Use the payload data in the webhook request to authenticate the user

    EDIT

    When using Dialogflow-Messenger, you don't have access to the Dialogflow API directly; however, for the step 3, you can still pass a value to queryParams.payload through the user-id HTML customization.

    user-id value in HTML customization

    Here's an example of how to set it dynamically:

    const dfMessenger = document.querySelector('df-messenger');
    dfMessenger.setAttribute("user-id", YOUR_USER); // Sent to Dialogflow API through queryParams.payload