Skip to content

[BUG] Basic Auth #4498

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

Closed
wm-ek opened this issue May 23, 2025 · 11 comments · Fixed by #4501
Closed

[BUG] Basic Auth #4498

wm-ek opened this issue May 23, 2025 · 11 comments · Fixed by #4501

Comments

@wm-ek
Copy link

wm-ek commented May 23, 2025

Basic auth requires both username and password.

There are services, that will have a token as username and that's it.

Due to the validation, we can not authenticate with a service which implemented it that way

Authentication to the API is performed via HTTP Basic Auth. Provide your API key as the basic auth username value. You do not need to provide a password. This is done for every request, not just once.

It would be great to make password optional.

thank you

@HenryHengZJ
Copy link
Contributor

We are changing the authentication method to use JWT based with email & password login. Unfortunately it will be a must by default to set an email & password

@wm-ek
Copy link
Author

wm-ek commented May 24, 2025

i was talking about the http node, just to clarify.

where i make a coll to an external api to get some data

@HenryHengZJ

@HenryHengZJ
Copy link
Contributor

ohhh okay got it, does it cause error if you dont have password on the basic auth?

@HenryHengZJ HenryHengZJ reopened this May 24, 2025
@wm-ek
Copy link
Author

wm-ek commented May 24, 2025

@HenryHengZJ yes, i get a 401

Image

@korade-krushna
Copy link
Contributor

Can I pick this issue, as what I understood from the context, we just need to keep username requiured and password as optional in basic auth while calling external services ?

@wm-ek
Copy link
Author

wm-ek commented May 24, 2025

@korade-krushna yes, thank you

@korade-krushna
Copy link
Contributor

@wm-ek Do you have any external service which uses username as token in basic auth, which I can use to reproduce the issue

@wm-ek
Copy link
Author

wm-ek commented May 24, 2025

@korade-krushna actually not. sorry. i believe postman could capture the request: https://learning.postman.com/docs/sending-requests/capturing-request-data/capture-overview/ or a n8n/make webhook

header should look like
Authorization: Basic <password>

@korade-krushna
Copy link
Contributor

Whatever I got says this is not standard way to ue basic auth @wm-ek , can you point me to the service where you got this error

Authentication to the API is performed via HTTP Basic Auth. Provide your API key as the basic auth username value. You do not need to provide a password. This is done for every request, not just once.

Or could you please paste steps to reproduce this issue

@wm-ek
Copy link
Author

wm-ek commented May 25, 2025

@korade-krushna well, i did not develop that api-service.

its not possible to use withoutl licence. however, here are the api docs: https://app.cashctrl.com/static/help/en/api/index.html#auth

@korade-krushna
Copy link
Contributor

@wm-ek
Reproduced your bug with below python server

from fastapi import FastAPI, Depends, HTTPException, status
from fastapi.security import HTTPBasic, HTTPBasicCredentials
from starlette.requests import Request
import secrets

app = FastAPI()
security = HTTPBasic()

# Replace with your actual API key
VALID_API_KEY = "1234567890"

def authenticate(credentials: HTTPBasicCredentials = Depends(security)):
    print(credentials)
    correct_username = secrets.compare_digest(credentials.username, VALID_API_KEY)
    correct_password = credentials.password in (None, "",)  # Accept no password

    if not correct_username or not correct_password:
        print("Invalid API Key")
        raise HTTPException(
            status_code=status.HTTP_401_UNAUTHORIZED,
            detail="Invalid API Key",
            headers={"WWW-Authenticate": "Basic"},
        )
    return credentials.username

@app.get("/api/data")
def read_data(username: str = Depends(authenticate)):
    return {"message": "Access granted", "user": username, "data": "Here's your secure data"}

Tested it with passing only the key(without : in the end) in the username keeping password empty, it works fine

Image

HenryHengZJ pushed a commit that referenced this issue May 27, 2025
)

Use Correct Key For Basic Auth and Optional pass

Co-authored-by: Krishna Korade <[email protected]>
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

Successfully merging a pull request may close this issue.

3 participants