diff --git a/authentik/api/templates/api/swagger.html b/authentik/api/templates/api/swagger.html index 133f6f86f..f0b99181c 100644 --- a/authentik/api/templates/api/swagger.html +++ b/authentik/api/templates/api/swagger.html @@ -11,6 +11,29 @@ authentik API Browser {% endblock %} {% block body %} +<script> +function getCookie(name) { + let cookieValue = ""; + if (document.cookie && document.cookie !== "") { + const cookies = document.cookie.split(";"); + for (let i = 0; i < cookies.length; i++) { + const cookie = cookies[i].trim(); + // Does this cookie string begin with the name we want? + if (cookie.substring(0, name.length + 1) === name + "=") { + cookieValue = decodeURIComponent(cookie.substring(name.length + 1)); + break; + } + } + } + return cookieValue; +} +window.addEventListener('DOMContentLoaded', (event) => { + const rapidocEl = document.querySelector('rapi-doc'); + rapidocEl.addEventListener('before-try', (e) => { + e.detail.request.headers.append('X-CSRFToken', getCookie("authentik_csrf")); + }); +}); +</script> <rapi-doc spec-url="{{ path }}" heading-text="authentik"