-
-
Notifications
You must be signed in to change notification settings - Fork 20.5k
[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
Comments
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 |
i was talking about the http node, just to clarify. where i make a coll to an external api to get some data |
ohhh okay got it, does it cause error if you dont have password on the basic auth? |
@HenryHengZJ yes, i get a 401 |
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 ? |
@korade-krushna yes, thank you |
@wm-ek Do you have any external service which uses username as token in basic auth, which I can use to reproduce the issue |
@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 |
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
Or could you please paste steps to reproduce this issue |
@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 |
@wm-ek 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 ![]() |
) Use Correct Key For Basic Auth and Optional pass Co-authored-by: Krishna Korade <[email protected]>
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
It would be great to make password optional.
thank you
The text was updated successfully, but these errors were encountered: