Pass basic auth parameter to task
Hey !
I would like to know your best practice for following scenario:
The swagger endpoint is protected with basic auth. How could I pass username and password for the task to access the open api docs?
Or should I re-configure my setup?
I have a Spring Boot 3, Kotlin, regular WebMVC application and want to generate docs.
Thank you very much in advance for any possible help :)
I guess there is currently no way to specify the authentication type and credentials. https://github.com/springdoc/springdoc-openapi-gradle-plugin/blob/e855f9c3aeb776f3d3ef285c80aca748c5a50950/src/main/kotlin/org/springdoc/openapi/gradle/plugin/OpenApiGeneratorTask.kt#L77-L80
mhm. do you have an idea how I could do it easily anyways? 🤔
With current implementation, it's not possible. What you can do is to create a PR, where you add a new plugin parameter: headers as map of key-values. Then you set those headers into connection request:
val connection: HttpURLConnection =
URL(url).openConnection() as HttpURLConnection
connection.requestMethod = "GET"
headers.forEach { connection.setRequestProperty(it.key, it.value) }
connection.connect()
To test this out I believe you can create a test endpoint which will serialise all request headers and will return them. Then you can validate that all headers are present.
Hi @vonWojtas @JiangHongTiao I have an open PR https://github.com/springdoc/springdoc-openapi-gradle-plugin/pull/144 , might also apply to this use-case
cc @bnasslahsen
https://github.com/springdoc/springdoc-openapi-gradle-plugin/pull/144 should resolve this issue.