JSON:API with django-rest-framework-json-api and JWT












0















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?










share|improve this question





























    0















    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?










    share|improve this question



























      0












      0








      0








      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?










      share|improve this question
















      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






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 24 '18 at 14:29







      Gurkenkönig

















      asked Nov 24 '18 at 14:19









      GurkenkönigGurkenkönig

      285518




      285518
























          1 Answer
          1






          active

          oldest

          votes


















          1














          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.






          share|improve this answer























            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
            });


            }
            });














            draft saved

            draft discarded


















            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









            1














            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.






            share|improve this answer




























              1














              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.






              share|improve this answer


























                1












                1








                1







                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.






                share|improve this answer













                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.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 24 '18 at 21:23









                jelhanjelhan

                2,4541823




                2,4541823
































                    draft saved

                    draft discarded




















































                    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.




                    draft saved


                    draft discarded














                    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





















































                    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







                    Popular posts from this blog

                    Create new schema in PostgreSQL using DBeaver

                    Deepest pit of an array with Javascript: test on Codility

                    Costa Masnaga