JSON:API with django-rest-framework-json-api and JWT
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.nnReturns 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?
django django-rest-framework jwt json-api django-rest-framework-jwt
add a comment |
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.nnReturns 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?
django django-rest-framework jwt json-api django-rest-framework-jwt
add a comment |
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.nnReturns 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?
django django-rest-framework jwt json-api django-rest-framework-jwt
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.nnReturns 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?
django django-rest-framework jwt json-api django-rest-framework-jwt
django django-rest-framework jwt json-api django-rest-framework-jwt
edited Nov 24 '18 at 14:29
Gurkenkönig
asked Nov 24 '18 at 14:19
GurkenkönigGurkenkönig
285518
285518
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Your payload is not a valid JSON API document. It must have a resource object or a collection of resource objects on data
key. A resource object must have id
and type
members. Attributes should be represented as an attributes object on attributes
key.
The error reported seems to be related to missing type
member. Therefore it assumes a type of None
, which is "not the type that constitute the collection represented by the endpoint". The last part seems to be specific to Django REST Framework JSON API implementation.
Please note that JSON API specification is agnostic about authentication, so it's up to your implementation. You don't have to use a JSON API resource object to represent credentials. Often JSON API is not used for auth related endpoints cause standards for authentication implemented or conventions established are suggesting another payload structure for this endpoints.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53459090%2fjsonapi-with-django-rest-framework-json-api-and-jwt%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Your payload is not a valid JSON API document. It must have a resource object or a collection of resource objects on data
key. A resource object must have id
and type
members. Attributes should be represented as an attributes object on attributes
key.
The error reported seems to be related to missing type
member. Therefore it assumes a type of None
, which is "not the type that constitute the collection represented by the endpoint". The last part seems to be specific to Django REST Framework JSON API implementation.
Please note that JSON API specification is agnostic about authentication, so it's up to your implementation. You don't have to use a JSON API resource object to represent credentials. Often JSON API is not used for auth related endpoints cause standards for authentication implemented or conventions established are suggesting another payload structure for this endpoints.
add a comment |
Your payload is not a valid JSON API document. It must have a resource object or a collection of resource objects on data
key. A resource object must have id
and type
members. Attributes should be represented as an attributes object on attributes
key.
The error reported seems to be related to missing type
member. Therefore it assumes a type of None
, which is "not the type that constitute the collection represented by the endpoint". The last part seems to be specific to Django REST Framework JSON API implementation.
Please note that JSON API specification is agnostic about authentication, so it's up to your implementation. You don't have to use a JSON API resource object to represent credentials. Often JSON API is not used for auth related endpoints cause standards for authentication implemented or conventions established are suggesting another payload structure for this endpoints.
add a comment |
Your payload is not a valid JSON API document. It must have a resource object or a collection of resource objects on data
key. A resource object must have id
and type
members. Attributes should be represented as an attributes object on attributes
key.
The error reported seems to be related to missing type
member. Therefore it assumes a type of None
, which is "not the type that constitute the collection represented by the endpoint". The last part seems to be specific to Django REST Framework JSON API implementation.
Please note that JSON API specification is agnostic about authentication, so it's up to your implementation. You don't have to use a JSON API resource object to represent credentials. Often JSON API is not used for auth related endpoints cause standards for authentication implemented or conventions established are suggesting another payload structure for this endpoints.
Your payload is not a valid JSON API document. It must have a resource object or a collection of resource objects on data
key. A resource object must have id
and type
members. Attributes should be represented as an attributes object on attributes
key.
The error reported seems to be related to missing type
member. Therefore it assumes a type of None
, which is "not the type that constitute the collection represented by the endpoint". The last part seems to be specific to Django REST Framework JSON API implementation.
Please note that JSON API specification is agnostic about authentication, so it's up to your implementation. You don't have to use a JSON API resource object to represent credentials. Often JSON API is not used for auth related endpoints cause standards for authentication implemented or conventions established are suggesting another payload structure for this endpoints.
answered Nov 24 '18 at 21:23
jelhanjelhan
2,4541823
2,4541823
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53459090%2fjsonapi-with-django-rest-framework-json-api-and-jwt%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown