I built an API that uses CSRF-Cookies for authentification. Now I want to document this API using OpenAPI/Swagger.
All routes are protected by a middleware that verifies the CSRF-Token, except for /sanctum/csrf-cookie
, which is used to initially retrieve the Token.
Therefore, I need the Swagger-UI to include the cookie on each request. I followed the documentation, but it does not work.
Here's an excerpt from my Swagger-Definition:
security:
- cookieAuth: []
paths:
/sanctum/csrf-cookie:
get:
operationId: "getApiToken"
responses:
'204':
description: "successful token retrieval"
headers:
Set-Cookie:
schema:
type: string
/login:
post:
operationId: "loginUser"
requestBody:
content:
application/json:
schema:
type: "object"
properties:
username:
type: string
password:
type: string
components:
securitySchemes:
cookieAuth:
type: apiKey
in: cookie
name: XSRF-TOKEN
As seen in the screenshot of my browsers network monitor, the headers of login
request do not contain the XSRF-Token.
In Contrast, this is the exact same request sent by my frontend: