Actix-web gives 415 Unsupported Media Type instead of JSON

Starting to implement a very small solution for authentication (starting with RFC6749's password grant flow). Unfortunately I can't seem to hit an endpoint without succumbing to this error.

Here's my open licensed repo:

Replication:

curl -X POST http://localhost:8080/token \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-d '{"grant_type": "password", "username": "user", "password": "pass"}'

The /token handler takes a form as its data, not a JSON structure. You should change web::Form to web::Json, or alternatively submit a form-urlencoded data payload, e.g.

curl --verbose -X POST http://localhost:8080/token \
-H "Content-Type: application/x-www-form-urlencoded" \
-H "Accept: application/json" \
-d "grant_type=password&username=user&password=pass"
1 Like

:man_facepalming:

Wow what a n00b mistake by me.

Thanks for the assist

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.