1
votes

The Oauth2 documentation for google doesnt contain (that I have seen yet) Information on what I am trying to do.

From my server I want to post request to my google cloud to get a response.

For this I need an access token, currently i'm taking it manually from the playground. I am going from my server to my cloud and the documentation states about a user accepting access and then being redirected etc but I don't involve any users.

  • I need to continuously, automatically get an access token for my requests, or similar. Without needing to click for access?

this is the request, for context:

var options = {
        method: 'POST',
        uri: 'https://dialogflow.googleapis.com/v2beta1/projects/someproject/agent/sessions/1:detectIntent',
        headers: {
            'Authorization': 'Bearer ya29.GlsGBscelmqeHgOVgx1p4EF_L45zetym6s3isC1HF4IYJqb20vHd8FolxvsmM_vU2fmIPWN3JElGIEuNN3i_-N9V-68YlwNvEduMIA5SuSltK-Sepsl0yNYM9REy',
            'Content-Type': 'application/json'
        },
        body: {
            "queryInput": {
                "event": {
                    "name": "Matching",
                    "languageCode": "en"
                }
            }
        },
        json: true // Automatically stringifies the body to JSON
    };

For more information, I am triggering an intent from dialogflow.

1
Could you find a solution to that? It would be nice, if you come back and document your final solution here, so everyone can benefit. - Mohsenne

1 Answers

1
votes

If the application does not involve user interaction, and if you would like to automate the authentication method, you should use service accounts, notably, you could use the JSON Web Token (JWT) or the Google ID Access token to authenticate between services.

For more information in this regard, you may follow this article in the GCP documentation.

You may also find useful information in this StackOverflow thread. It offers help on how to pass a token through DialogFlow.