Is there any example on how to use spring security with graphql-spqr?

239 views Asked by At

Looking for example on how to implement spring boot role based authentication and authorization for graphql-spqr project using spring security.

Tried using spring-boot-starter-security but having issues while using playground. Getting below error

{ "error": "Unexpected end of JSON input" }

Click here to see error details

1

There are 1 answers

3
kaqqao On

In general there's nothing special about how SPQR interacts with Spring Security. You set up your security the same as ever, and it should behave as expected. The error you're getting is a bit unfortunate, because Spring will normally return a body-less 401 when authorization fails, and playground expects a JSON body, hence the "Unexpected end of JSON input".

How do you normally authenticate to your server? Session cookie? Access token? Whatever it is, you have to tell your client (GraphiQL, Playground, etc) to send it together with the query. There's a button that lets you add headers, so you can insert an Authorization there, for example. If you share more details about how auth works in your project, I can give a more specific answer.