swagger-api / swagger-api/swagger-codegen
CSRF Token Missing
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
This is a question about using a CSRF cookie name/header name with the generated JS library.
Swagger-codegen version
2.2.1
Swagger declaration file content or url
Command line used for generation
java -jar ~/Downloads/swagger-codegen-cli-2.2.1.jar generate -l javascript -i ~/Downloads/schema.json -o ~/Documents/heathcliff/clients/javascript
Steps to reproduce
N/A
Related issues/PRs
Suggest a fix/enhancement
Okay, so to get a broader sense of what I am doing:
- I am using Docker/NGINX/Gunicorn to serve up a Django DRF application
- The application uses session authentication.
- I have an endpoint, using drf_yasg, to generate a JSON schema file.
- I then generate the javascript client.
- I upload this generated client to npm
- I use webpack to stuff into budle.js
- When I use the sample code in the markdown file, provided by client docs, I get a 403 error indicating that the CSRF token is missing
Question is: how can I tell the JS client to use a CSRF token. In COREAPI, i can do something like:
var coreapi = window.coreapi;
// Initialize a client & load the schema document
var url = 'https://localhost/api/v1/schema.json';
var auth = new coreapi.auth.SessionAuthentication({
csrfCookieName: 'csrftoken',
csrfHeaderName: 'X-CSRFToken'
})
var client = new coreapi.Client({ auth: auth })
is there something similar with the generated JS code? Do i have to specify a security parameter in settings.py besided basic?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by inspecting the generated JavaScript client's request and authentication code and the sample client documentation, then compare its requests with Django REST Framework's CSRF requirements. Done means the generated client can be configured to send the configured CSRF cookie and header, and the documented request no longer receives a 403.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- django, docker, javascript, nginx, python, webpack
- Domain
- api, authentication, security
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100