swagger-api / swagger-codegen

swagger-codegen contains a template-driven engine to generate documentation, API clients and server stubs in different languages by parsing your OpenAPI / Swagger definition.
http://swagger.io
Apache License 2.0
17.04k stars 6.03k forks source link

CSRF Token Missing #7843

Open dhicksNTIA opened 6 years ago

dhicksNTIA commented 6 years ago
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:

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?

macjohnny commented 6 years ago

which JS client are you using? e.g. with angular, there is a default mechanism that uses the cookie named XSRF-TOKEN and sends it as a header named X-XSRF-TOKEN (https://github.com/angular/angular/blob/master/packages/common/http/src/module.ts#L94 and https://github.com/angular/angular/blob/master/packages/common/http/src/xsrf.ts#L90)