lucasheld / uptime-kuma-api

A Python wrapper for the Uptime Kuma Socket.IO API
https://uptime-kuma-api.readthedocs.io
MIT License
273 stars 23 forks source link

Custom Headers on login #20

Closed hegerdes closed 1 year ago

hegerdes commented 1 year ago

Thank for this API since the official one is still missing.

I would really want to use Uptime-Kuma but we need programmatic access to the API for configuration, so this API is the perfect fit (even with ansible support 👍). But I use custom authentifikation which is handelnd by a reverse proxy, so that I can use oauth and other nice features.

Unfortunately the API only supports Uptime-Kuma own auth mechanism and the is no native way to change it. It would be really nice to allow custom auth or at least set extra header on the initial socketIO connection.

Right now I solved it by overriding the connect method:

class UptimeKumaApiExtended(UptimeKumaApi):

    def connect(self) -> None:
        """
        Connects to Uptime Kuma.

        Called automatically when the UptimeKumaApi instance is created.

        :raises UptimeKumaException: When connection to server failed.
        """
        url = self.url.rstrip("/")
        try:
            self.sio.connect(f'{url}/socket.io/', wait_timeout=self.wait_timeout, headers=headers)
        except:
            raise UptimeKumaException("unable to connect")

Is there a option to support this use case naively?

If you are open for collaboration I can provide a example implementation in the near future.

lucasheld commented 1 year ago

Sure. Custom headers can be implemented like this: https://github.com/lucasheld/uptime-kuma-api/compare/master...feature/custom-headers

It would be really nice to allow custom auth or at least set extra header on the initial socketIO connection.

What do you mean by "custom auth or at least set extra header"? What other ways exist to implement the authentification?

The connect method also has a auth parameter. Is it useful? https://python-socketio.readthedocs.io/en/latest/api.html?highlight=auth#socketio.AsyncClient.connect

hegerdes commented 1 year ago

Perfect this change would really help me and I don`t need my extended class anymore :)

Right now I only need to pass extra headers. There are a million different ways to do auth but headers would cut most use-cases for now I think. Implementierung a own OIDC or oauth2 client would be overkill I think.

Thanks a lot for your fast response and your work!

lucasheld commented 1 year ago

Included in release 0.13.0.