-
Notifications
You must be signed in to change notification settings - Fork 31
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
JSON API: add support for login using JSON data #607
base: master
Are you sure you want to change the base?
Conversation
The JSON API login endpoint delegates to the WebGateway LoginView logic which only support form data defined in the login form. This commit proposes to extend the LoginView.post() logic to also support authentication sent at JSON data.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had not seen the len(request.POST) > 0
check before, but it should do what we want here. Code looks good to me.
I found through debugging this was one of the ways to distinguish between a HTTPRequest form data and JSON data. I am still not 100% happy with this approach which looks fragile and I am considering using the value of |
If I try something invalid like:
I get a 500 html response (since I have DEBUG true) with
|
This allows to use the consume the form validation logic when the login request is sent as JSON
Thanks @will-moore, I hadn't tested the failing scenarios. After discussion with @knabar, pushed 42790d5 to 1- use the content type to detect JSON POST requests, 2- pass the JSON as a dictionary as an input to ome/openmicroscopy#6420 should included updated integration tests for both valid and rejected JSON POST requests |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Working fine, thanks.
Tested successful login with data
and json
and invalid login with data
and json
. All with expected results.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works as expected
Discovered while using the JSON API and failing to authenticate using
curl --json
. It took me a while to figure out this undocumented limitation especially since other JSON API POST endpoints expect the data to be sent as JSON.The JSON API login endpoint delegates to the WebGateway LoginView logic which only support form data defined in the login form. This commit proposes to extend the LoginView.post() logic to also support authentication sent at JSON data.
There are a few ways to test this change:
curl --json
with the appropriate headersrequests.post(login_url, json=payload)
e.g. by modifying https://github.com/ome/openmicroscopy/blob/1ae1bfa5b831dc0225df48dbef7871cc6ab044f6/examples/Training/python/Json_Api/Login.py#L70 to usejson
rather thandata
This change should not affect the ability to log in using the login page or the JSON API with form data.