Hello,
I have been learning about how to create http endpoints inside anvil and I ran into an issue with the basic authentication using users service.
Here is a link to the docs:
I set up the endpoint just like the example shows, however when I send the email and password through postman I get an Unathorized error. I also tried to send it with curl like the example shows, but I get the same error.
The only way it works is if I open the endpoint in a browser, where an authentication window pops up and requests the email and password.
My server side code:
@anvil.server.http_endpoint("/protected1", authenticate_users=True)
def serve_protected_content():
return {"authentication":"successful","users_email":request.user['email']}
Url:
https://[MY_CUSTOM_DOMAIN]/_/api/protected1
Curl command:
curl -u [USER_EMAIL]:[USERS_PASSWORD] https://[MY_CUSTOM_DOMAIN]/_/api/protected1
Result : Unauthorized
Browser link:
https://[MY_CUSTOM_DOMAIN]/_/api/protected1
Result: {“authentication”:“successful”,“users_email”:[THE_GIVEN_EMAIL]}
Postman:
Basic Authentication with email and password and the postman’s standard headers (Postman-token, content-length,…)
Body: None
Params: None
Result: Unathorized
I also tried changing the endpoint to
@http_endpoint("/protected", require_credentials=True)
This way I recieve the sent email and password, but I have to authenticate the users myself. At the moment I do not need more complicated authentications with tokens, so I would settle with the first one, if it worked.
I also found another topic regarding this from April, unfortunately it was ignored.
The topic’s link:
Am I missing something or misunderstood the documentation, that this should work?
Can somebody help with this?
Thanks in advance,
Arpad