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

Example for POST login via JSON in body #863

Open
bernhardreiter opened this issue Jun 16, 2020 · 1 comment
Open

Example for POST login via JSON in body #863

bernhardreiter opened this issue Jun 16, 2020 · 1 comment

Comments

@bernhardreiter
Copy link
Contributor

It would be useful to have an example that allows for a login using JSON as body in a POST request. Use case: have an example for a single page web applicaton that likes to protect
against CSRF via an access token.

The current example https://github.com/hugapi/hug/blob/develop/examples/authentication.py#L76 token_gen_call() will also accept URL parameters, which it shouldn't. As a plus it probably should also check if there are extra parameters and fail, if there are.

@bernhardreiter
Copy link
Contributor Author

Right now, this is how it can work with current hug, with test requests from curl.

hug -f hug-git/examples/authentication.py -p 8022
# different shell
curl "localhost:8011/token_generation"  -H "Content-Type: application/json" --data-raw '{"username":"User2", "password":"Mypassword"}'
# put the returned value in the shell variable TOKEN
set TOKEN abcd123...
curl "localhost:8011/token_authenticated"  -H "Authorization: $TOKEN"

bad case1 url parameters

 curl "localhost:8011/token_generation?username=User2&password=Mypassword"  -H "Content-Type: application/json" --data-raw '{}'
# succeeds, but shouldn't

bad case2 additional parameters

curl "localhost:8011/token_generation"  -H "Content-Type: application/json" --data-raw '{"username":"User2", "password":"Mypassword", "yoyo":"somemore"}'
# succeeds, but shouldn't

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