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

Inconsistent Behavior with Trailing Slash in URL During Authentication #447

Open
kirianguiller opened this issue Nov 27, 2023 · 0 comments

Comments

@kirianguiller
Copy link

kirianguiller commented Nov 27, 2023

Description

I've encountered inconsistent behavior in the library when a trailing slash is present in the URL during the authentication process. Specifically, the behavior differs depending on the authentication method used.

Issue Details

In all following explanation, hass_url is the machine hass url and port

  • With Normal Authentication: The library functions correctly both with and without a trailing slash in the URL. For example, http://hass_url and http://hass_url/ both work as expected.
  • With Long Lived Tokens: The library fails to authenticate when the URL includes a trailing slash. For example, http://hass_url/ does not work (further connection returns 404 error code), whereas http://hass_url works correctly.

Steps to Reproduce

  1. Use the normal authentication method with the URL http://hass_url/ with trailing slash – Observe that it succeeds.
  2. Use the normal authentication method with the URL http://hass_url without trailing slash – Observe that it succeeds.
  3. Use authentication with long-lived tokens with the URL http://hass_url/ with trailing slash – Observe that it fails.
  4. Use authentication with long-lived tokens with the URL http://hass_url without trailing slash – Observe that it succeeds.

Code :

// shared variables
const HASS_URL_WITHOUT_TRAILING_SLASH =  "your_hass_url";
const HASS_URL_WITH_TRAILING_SLASH = "yout_hass_url/";
let auth;

// 1 and 2
auth = await getAuth({hassUrl: HASS_URL_WITH_TRAILING_SLASH}); // further connection will works
auth = await getAuth({hassUrl: HASS_URL_WITHOUT_TRAILING_SLASH}); // further connection will works

// 3 and 4
const ACCESS_TOKEN = "your_access_token";
auth = createLongLivedTokenAuth(HASS_URL_WITH_TRAILING_SLASH, ACCESS_TOKEN);  // further connection will NOT works
auth = createLongLivedTokenAuth(HASS_URL_WITHOUT_TRAILING_SLASH, ACCESS_TOKEN);  // further connection will works

// shared further connection
const conn = await createConnection({ auth: auth });

Expected Behavior

The library should consistently handle URLs with or without a trailing slash in both authentication methods.

Actual Behavior

The library only fails with a trailing slash in the URL when using authentication with long-lived tokens (further connection returns 404 error code).

Environment

Library version: 8.2.0
Environment/OS: Ubuntu 23.04

Thanks a lot for your nice lib :)

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

1 participant