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

Connection via JWT not possible #14

Open
fatualux opened this issue Feb 3, 2025 · 0 comments · May be fixed by #15
Open

Connection via JWT not possible #14

fatualux opened this issue Feb 3, 2025 · 0 comments · May be fixed by #15
Labels
bug Something isn't working

Comments

@fatualux
Copy link

fatualux commented Feb 3, 2025

🐛 Describe the bug

Hi and thanks for your work.
I connect to the CCat via custom auth handler (JWT), but this library does not allow to connect with an adding token.
If I try to connect, I get the following error:

ERROR - Handshake status 403 Forbidden -+-+- {'date': 'Mon, 03 Feb 2025 21:30:49 GMT', 'content-length': '0', 'content-type': 'text/plain', 'connection': 'close'} -+-+- b'' - goodbye
INFO - Connection with id admin closed with code None: None

I think the problem is that ws_connect method in cat_client.py does not accept arguments, which could extend url:

    def connect_ws(self):
        protocol = "wss" if self._conn_settings.secure_connection else "ws"
        url = f"{protocol}://{self._conn_settings.base_url}:{self._conn_settings.port}/ws/{self._conn_settings.user_id}"

I have found a workaround to solve this issue:

    def connect_ws(self):
        protocol = "wss" if self._conn_settings.secure_connection else "ws"
        url = f"{protocol}://{self._conn_settings.base_url}:{self._conn_settings.port}/ws/{self._conn_settings.user_id}"
        if self._conn_settings.auth_key:
            url += f"?token={self._conn_settings.auth_key}"

So, if argument auth_key is provided in ccat.Config , url is extended with the needed string plus JWT.

I will do a PR to propose this little fix.

Versions

admin >>main U:2 ?:2 >>p❳ .venv >~/Debian/cattest>python --version && pip freeze
Python 3.11.2
annotated-types==0.7.0
certifi==2025.1.31
charset-normalizer==3.4.1
cheshire_cat_api==1.4.8
idna==3.10
pydantic==2.10.6
pydantic_core==2.27.2
python-dateutil==2.9.0.post0
python-dotenv==1.0.1
requests==2.32.3
six==1.17.0
typing_extensions==4.12.2
urllib3==2.0.7
websocket-client==1.8.0

@fatualux fatualux added the bug Something isn't working label Feb 3, 2025
@fatualux fatualux linked a pull request Feb 3, 2025 that will close this issue
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant