I thought it might be a good idea to use the standard JSON:API for my new project. Unfortunately I immediately failed to get the JWT authentication working. My setup:
- Django
- Django REST framework
- REST framework JWT Auth
- Django REST Framework JSON API
If I get OPTIONS for my auth path:
{
"data": {
"name": "Obtain Json Web Token",
"description": "API View that receives a POST with a user's username and password.\n\nReturns a JSON Web Token that can be used for authenticated requests.",
"renders": [
"application/vnd.api+json",
"text/html"
],
"parses": [
"application/vnd.api+json",
"application/x-www-form-urlencoded",
"multipart/form-data"
],
"allowed_methods": [
"POST",
"OPTIONS"
],
"actions": {
"POST": {
"username": {
"type": "String",
"required": true,
"read_only": false,
"write_only": false,
"label": "Username"
},
"password": {
"type": "String",
"required": true,
"read_only": false,
"write_only": true,
"label": "Password"
}
}
}
}
}
If I then try to POST naively with Content-Type: application/vnd.api+json:
{
"data": {
"user": "user1",
"password": "supersecretpw"
}
}
I get 409 Conflict response:
{
"errors": [
{
"detail": "The resource object's type (None) is not the type that constitute the collection represented by the endpoint (ObtainJSONWebToken).",
"source": {
"pointer": "/data"
},
"status": "409"
}
]
}
How can I either retrieve the token correctly or use the above mentioned packages correctly?