lovelylain / hass_ingress

Home Assistant ingress feature, add additional ingress panels to your Home Assistant frontend.
Apache License 2.0
31 stars 6 forks source link

Passing url parameters #5

Closed mutasim closed 3 months ago

mutasim commented 3 months ago

My config:

blue_iris:
  title: Blue Iris
  icon: mdi:camera
  url: http://10.0.10.12
  ui_mode: toolbar
  index: /ui3.htm

This works and allows me to access the above resource at [hass URL]/blue_iris

Is it possible to pass a url parameter through? Sometimes I want to be able to link directly to http://10.0.10.12/ui3.htm?tab=clips or http://10.0.10.12/ui3.htm?tab=alerts&alert_id=123436456.

I tried [hass URL]/blue_iris?tab=clips but it didn't pass through the url params.

My use case is being able to deeplink to CCTV camera clips from Hass notifications. If this isn't possible yet, could I please make this a feature request?

lovelylain commented 3 months ago

If you solve the issue with absolute links, it should work. #4

mutasim commented 3 months ago

I think this issue is still relevant.

I've updated my comment above as some of the url was stripped out because of the markdown I was using. Hopefully it's clearer now..

lovelylain commented 3 months ago

I understand what you mean now. I want to know the usage scenario here. Add an index parameter to overwrite the one configured in the configuration file. You need to URL encode this parameter. Can it meet your needs? For example, use [hass URL]/blue_iris?index=ui3.htm%3Ftab%3Dclips to access http://10.0.10.12/ui3.htm?tab=clips

mutasim commented 3 months ago

I think your proposal is great because others might have different paths they want to deeplink to rather than just URL params. Sounds like your approach gives maximum flexibility to deeplink into other pages within the app or add URL params to the same index page. 👍

For my use case, I'll be linking from a push notification to open the mobile app.

lovelylain commented 3 months ago

supported in 1.0.3

mutasim commented 3 months ago

Wow that was quick! I'll test and report back.

mutasim commented 3 months ago

Tested with url params and with a different path altogether.. works great!! thanks

TinyShark commented 2 months ago

Hi @mutasim - thanks for raising this as it's helped me get my BI working.

I was wondering what you are doing for authentication? It doesn't prompt me for login when using the HA iOS app.

It would be amazing if we could have home assistant authenticate, per user, with BI and remove the need for any additional login prompts.

mutasim commented 2 months ago

I have it setup so all of my HA users are effectively the same BI user. So there's no per user auth/profiles.

mutasim commented 2 months ago

You might be able to pass BI auth credentials via URL params and use templates to do different values for each HA user (?)

lovelylain commented 2 months ago

@TinyShark if your service use basic auth, you can add authorization header to bypass the authentication in ingress work_mode.

TinyShark commented 2 months ago

@mutasim Thanks for the heads up, I have been doing just that for an iframe card but it has been less than reliable unfortunately. I think Blue Iris is partly to blame with it's session management but can give it another go.

@lovelylain Many thanks for this, really useful integration!

There is unfortunately very little documentation for this from Blue Iris but I do know that it 1) supports basic auth and 2) someone else has had success attempting Single Sign-On and that it will look for the Remote-User header from a proxy, and authorize that user if it exists in the BI auth db.

He also confirmed it working from the command line using curl -I -H 'Remote-User: MY_USERNAME' -XGET http://blueiris.MY.DOMAIN

Would this be possible coming from HA/your integration and if so what would the yaml config look like?

Many thanks!

TinyShark commented 2 months ago

Cool! seems to be working with the below:

ingress:
  blue_iris:
    title: Blue Iris
    icon: mdi:camera
    url: http://IP:PORT
    ui_mode: normal
    index: /ui3.htm
    headers:
      Remote-User: 'your-user'

Last piece of the puzzle would be how to pull the current home assistant user and pass that as the Remote-User presumably I can't use a template like i would do in the front end?

mutasim commented 2 months ago

@TinyShark have you been able to work out how to save images/clips from BI when using the HA iOS app?

Also would be good to hear what your use case is for different BI users.

TinyShark commented 2 months ago

@mutasim I have not really looked into that yet as my main use case within HA is to simply view BI's UI3. I do have BI send images via MQTT to HA on certain triggers (e.g doorbell cam etc).

The reason I'd like to authenticate blue iris with different users is so that I can configure certain users/devices to specific camera groups and also different streaming schedules as defined in blue iris' user settings.

Looking at the docs for Ingress it seems that the header information could be available and for that to be passed on as a header through this component.

https://developers.home-assistant.io/docs/add-ons/security#authenticating-a-user-when-using-ingress

I'm wondering if in a similar fashion to:

name = request.headers.get('X-Ingress-Name')

you could have additional gets for the user id such as:

remote_user_id = request.headers.get('X-Remote-User-Id')
headers['Remote-User'] = remote_user_id

or user name etc:

remote_user_name = request.headers.get('X-Remote-User-Name')
headers['Remote-User'] = remote_user_name

and then in the config yaml we could put something like this:

ingress:
  panel:
    title: Blue Iris
    icon: mdi:icon
    url: http://X.X.X.X
    index: /ui3.htm
    forward_headers:
      Remote-User: true
lovelylain commented 2 months ago

@TinyShark Currently hass_ingress does not support passing user information. I already have an idea on how to pass user information, but it is a bit complicated and takes time to implement. Maybe you will be provided with a configuration item as shown below:

ingress:
  blue_iris:
    title: Blue Iris
    icon: mdi:icon
    url: http://X.X.X.X
    index: /ui3.htm
    user_headers:
      user_id_a:
        Remote-User: aaa
      user_id_b:
        Remote-User: bbb
TinyShark commented 2 months ago

@lovelylain Understood. And yes your configuration example is definitely a more elegant solution to this and would enable far more customization.

Very interested in your idea on how to accomplish getting the user information. I have been trying but with no success (though I am very far from being a developer 😸 )