Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

widget fails to authenticate #14

Open
swdwi2 opened this issue Feb 17, 2020 · 29 comments
Open

widget fails to authenticate #14

swdwi2 opened this issue Feb 17, 2020 · 29 comments

Comments

@swdwi2
Copy link

swdwi2 commented Feb 17, 2020

Thanks for the effort to produce the custom widgets.

I'm experiencing connection issues with the hagraph widget. Getting multiple errors I'm assuming related to CORS.

Appreciate if you have any ideas of where I should start looking to resolve this.

I'm using Home Assistant 0.105.4.

: Origin http://192.168.1.8:5050 is not allowed by Access-Control-Allow-Origin.

Please let me know which files I should provide to assist you in resolving this issue.
Safari Snapshot.txt

Attached is a sample of the messages I see in my java console.

Regards Dave

@tjntomas
Copy link
Owner

tjntomas commented Feb 18, 2020

I think you should try adding your appdaemon ip and port to your Home Assistant configuration.yaml file, in the http: section.
Here is an example:

http:
  cors_allowed_origins:
    - http://192.168.1.8:5050  # Your Appdaemon ip and port

This should take care of the CORS issue.
Also, a few things that would be good to know if the above does not help:

  • Are you using Appdaemon 3 or 4?
  • Are you running Appdaemon in Docker or a venv?
  • Are you using Home Assistant (formerly hassio) or Home Assistant Core, in venv or docker?

You also have some unrelated errors in your log, but let's start with the above.

@swdwi2
Copy link
Author

swdwi2 commented Feb 19, 2020 via email

@tjntomas
Copy link
Owner

Hi, nothing attached or maybe you were not allowed to attach anything here. Please post your appdaemon.yaml file to start with. You are getting some errors I havn't seen before so seems like a network issue. Also, the widgete was written for Appdaemon 3 and a few minor changes are need if you are ussing Appdaemon 4.

@swdwi2
Copy link
Author

swdwi2 commented Feb 19, 2020 via email

@tjntomas
Copy link
Owner

Ok, looks like I already made the changes in the repo, I forgot that.

This should not be needed in appdaemon.yaml so remove it for now:

  headers:
    Access-Control-Allow-Origin: "*"

Please post your http: section from your configuration.yaml file. It is strange that you are still receiving CORS errors if the http: section in HA is correct.

@tjntomas
Copy link
Owner

I also made some changes to the widget since I posted it, so when I get home I'll upload all changes. This has mostly to do with increased drawing speed and fetching data from HA.

@swdwi2
Copy link
Author

swdwi2 commented Feb 19, 2020 via email

@tjntomas
Copy link
Owner

tjntomas commented Feb 19, 2020

The V4 changes were made and uploaded to the repo some weeks ago so you should already have the correct files. I am also running both Appdaemon and HA in docker on Ubuntu 18.04 so this should not be an issue. For file permissions I use 755 but 644 should be enough.

@tjntomas
Copy link
Owner

I'll post here when I have uploaded the changed code.

@tjntomas
Copy link
Owner

tjntomas commented Feb 19, 2020

ok, so replace your existing basehagraph folder and hagraph.yaml file with the files in this repo
https://github.com/tjntomas/hagraph_debug

Then make a .dash file with only one hagraph widget (no other widgets at all in the file), empty the browser cache and see what the browser console log says. I had some errors also and I have updated the code and got rid of all errors.

@swdwi2
Copy link
Author

swdwi2 commented Feb 20, 2020 via email

@tjntomas
Copy link
Owner

Ok, access the page again and then quickly click on link in the log following the words [Error] XMLHttpRequest cannot load (it will gererante a new link each time so you need to click on the link within 20 seconds.
```` or copy the link to your browser. Also, please post the http: section from your `configuration.yaml `file. This is likely a simple problem, just something we are missing.

Please also post your .dash file. What url are you using to access Appdaemon?

@swdwi2
Copy link
Author

swdwi2 commented Feb 20, 2020 via email

@tjntomas
Copy link
Owner

Ok, great, the call to retrieve the history from HA is working fine.
In the widget, units: °W" should be units: "W" but I don't think this makes any different, but adjust it anyway. I have a few ideas I will post later regarding the CORS error.

@swdwi2
Copy link
Author

swdwi2 commented Feb 20, 2020 via email

@tjntomas
Copy link
Owner

http:
  cors_allowed_origins:
    - http://192.168.1.8:5050 <http://192.168.1.8:5050/>

Just checking to make sure its not a cut and paste issue, but the <http://192.168.1.8:5050/> should not be there, it should only be

http:
  cors_allowed_origins:
    - http://192.168.1.8:5050

@swdwi2
Copy link
Author

swdwi2 commented Feb 20, 2020 via email

@swdwi2
Copy link
Author

swdwi2 commented Feb 20, 2020 via email

@swdwi2
Copy link
Author

swdwi2 commented Feb 21, 2020 via email

@tjntomas
Copy link
Owner

I am also on 0.105.5, with the same CORS settings working which is the strange thing. I'm starting to suspect that the CORS configuration in HA is not working as expected. Any access errors in the HA logs?

@tjntomas
Copy link
Owner

tjntomas commented Feb 21, 2020

Please check the following:
Open the url to the dashboard in Chrome. Open the console and click on network and then select XHR and click on the line with a date. Then click on Headers and copy the content of the headers window. Start copying from the bottom is easier. Then same with the initiator section and copy the content in the Request initiator chain section and post it here. This will show the exact request and response of the XHTMLRequest used to access the history from HA.

@swdwi2
Copy link
Author

swdwi2 commented Feb 21, 2020 via email

@swdwi2
Copy link
Author

swdwi2 commented Feb 21, 2020 via email

@tjntomas
Copy link
Owner

Might be a namespace issue, one widget overwriting parameters for another widget, possibly the url parameter, causing a call to an unexpected url. I will have a look at using a separate namespace for the widget to see if the issue goes away.

@swdwi2
Copy link
Author

swdwi2 commented Feb 26, 2020 via email

@stibbzy
Copy link

stibbzy commented Oct 11, 2021

I am also on 0.105.5, with the same CORS settings working which is the strange thing. I'm starting to suspect that the CORS configuration in HA is not working as expected. Any access errors in the HA logs?

Hi @tjntomas , @swdwi2

I am having a very similar issue with CORS authentication. Here is what the javascript console shows whenever I attempt to use the widget. I also get an authentication error in the HA log, despite using the correct token:
Screen Shot

The start of my configuration.yaml looks like this:

default_config:
api:
http:
cors_allowed_origins:
- http://192.168.0.40/
- http://192.168.0.40:5050/
- http://homeassistant.local
- http://homeassistant.local/

I'm running Appdaemon 4, with Home Assistant in a VirtualBox VM. All other widgets can pull data fine. The relevant sections of my dashboard config, using the default skin, are:

title: Test Panel
widget_dimensions: [120, 120]
widget_margins: [5, 5]
columns: 8
use_hass_icon: 1

mvp:
widget_type: hagraph
entities:
- sensor.3rd_bed_temp_189 # The entity_id to be plotted.
units: "°C" # The unit_of_measurement for your sensors/entities
titles:
- "Indoor temperature" # Title of the trace.
time: 24h # Time interval to plot. you can combine w, d, h and m as 2w1d3h20m (This would be 2 weeks, 1 day, 3 hours and 20 minutes)
title: "Temperatures" # Widget title
value_in_legend: 1
fill: "tozeroy" # options are "none" | "tozeroy" | "tozerox" | "tonexty" | "tonextx" | "toself"
colorIndex: 0 # A number between 0 and 11. 12 colors for the traces are predefined and the colorIndex defines
# which is used for the first trace. If more than 12 traces/entities are specified, the colors are rotated.

layout:

  • mvp(2x1), label(3x1), side_humidity, mark_presence, porch_sensor

Per your instructions, I've copied the default skin variables and dashboard files to the custom_css folder and made the relevant changes. I then access it using http://192.168.0.40:5050/Test?skin=default

I thought @tjunussov had found the issue here (see the bottom of page): home-assistant/core#40513 but when I used his http folder as a custom component override, it still didn't fix the issue.

Do you have any other ideas? It's been driving me nuts for days now, I'd really love to have this graph functionality!

Many thanks :)

@tjntomas
Copy link
Owner

I'm currently travelling, so no access to my code, but try removing the trailing slash in http://192.168.0.40:5050/

@stibbzy
Copy link

stibbzy commented Oct 24, 2021

Hi @tjntomas
Thanks for the reply! I just tried your suggestion now, but unfortunately, the same authentication problem occurs.

@LouPaloma
Copy link

Was there ever a fix for the auth problem seen here? If not, are there any alternative graphing solutions?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants