Skip to content
This repository has been archived by the owner on Jul 20, 2023. It is now read-only.

No Access-Control-Allow-Origin Headers Present When Running on Browser #483

Closed
lauchness opened this issue Dec 8, 2019 · 8 comments
Closed
Labels
api: dialogflow Issues related to the googleapis/nodejs-dialogflow API. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. web

Comments

@lauchness
Copy link

Expected
When using the dialogflow.SessionsClient class, I would expect to be able to make calls to the dialogflow API and receive the appropriate CORS headers in the response.

Actual
When using the SessionsClient detectIntent method, the response from the dialogflow API doesn't contain the appropriate CORS headers (specifically "Access-Control-Allow-Origin"), preventing me from using this package in a browser.

Note: I used the auth parameter in the SessionsClient constructor outlined here: #405 (comment)

Environment details

  • Node.js version: 12.8.0
  • npm version: 6.10.3
  • dialogflow version: 0.14.1

Steps to reproduce

  1. Initialize SessionsClient class on Client application with OAuth2Client from google-auth-library package following these instructions: You need to pass auth instance to gRPC-fallback client. Use OAuth2Client from google-auth-library #405 (comment)

  2. Call detectIntent method from client application following the method in the dialogflow docs

@lauchness lauchness changed the title No Access-Control-Allow-Origin Headers Present When Running on Chrome No Access-Control-Allow-Origin Headers Present When Running on Browser Dec 8, 2019
@yoshi-automation yoshi-automation added the triage me I really want to be triaged. label Dec 8, 2019
@bcoe bcoe added type: question Request for information or clarification. Not an issue. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. and removed type: question Request for information or clarification. Not an issue. labels Dec 9, 2019
@bcoe
Copy link
Contributor

bcoe commented Dec 9, 2019

👋 while it should be possible to get our gRPC based libraries working in the browser (the process is detailed here). This is not something we support out of the box.

It might be worth commenting on the linked issue, regarding your requirements for CORS headers, if it doesn't seem like the process outlined would address this issue for you.

@yoshi-automation yoshi-automation removed the triage me I really want to be triaged. label Dec 9, 2019
@google-cloud-label-sync google-cloud-label-sync bot added the api: dialogflow Issues related to the googleapis/nodejs-dialogflow API. label Jan 30, 2020
@boehmrn
Copy link

boehmrn commented Feb 9, 2020

Did you manage to get it working? In your Example https://github.com/lauchness/dialog-flow, you only used the REST API. Im currently facing the same CORS issue, trying to implement an Electron Dialogflow client

@lauchness
Copy link
Author

@boehmrn I ended up just building an express server to handle the SessionsClient utilities.

At one point I had it working somewhat after passing OAuth2 in the constructor for SessionsClient, but it would only work for a Google Account with access to the bot, so it wasn't ideal. I haven't tried since early December though, and I know there have been updates since then.

@boehmrn
Copy link

boehmrn commented Feb 10, 2020

@lauchness Thanks for the quick reply. Because I want to handle streaming audio, setting up a express server (or socket server) increases the complexity. So it would be way more appealing to handle the SessionClient directly in the browser. I am using the same account for creating the Dialogflow agent und for the client. May you pass a Hint how you overcame the cors issue. how did you succeed? Is there an account setting?

@lauchness
Copy link
Author

I had first set up OAuth2 and used the response from that in the Constructor for the SessionsClient.

To set up OAuth2 you need to have a page which sends the user to the Google Auth page, and then another page to handle the redirect back from google with the token as a query param. It's outlined here: https://developers.google.com/identity/protocols/OAuth2UserAgent

Once you've got that taken care of the SessionsClient will work as expected, but like I said, in my experience this only worked if the Google Account used in OAuth2 had access to the dialogflow agent.

Sorry if it's not much help. I didn't go to deep into this once I abandoned using the browser.

@boehmrn
Copy link

boehmrn commented Feb 10, 2020

@lauchness
Ok thanks for helping. (Setting up oauth2 wasn't the problem). I think I will try the express server approach...

@lauchness
Copy link
Author

@boehmrn It will probably be worth it in the end anyway, good luck! Feel free to look here and see how I did it: https://github.com/lauchness/dialog-flow-server

@b-loved-dreamer
Copy link
Contributor

This issue might no longer be relevant due to its age. Feel free to re-open.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
api: dialogflow Issues related to the googleapis/nodejs-dialogflow API. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. web
Projects
None yet
Development

No branches or pull requests

6 participants