springdoc-openapi-gradle-plugin icon indicating copy to clipboard operation
springdoc-openapi-gradle-plugin copied to clipboard

Pass basic auth parameter to task

Open vonWojtas opened this issue 2 years ago • 4 comments

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 :)

vonWojtas avatar Nov 17 '23 13:11 vonWojtas

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

Donquih0te avatar Nov 21 '23 13:11 Donquih0te

mhm. do you have an idea how I could do it easily anyways? 🤔

vonWojtas avatar Nov 21 '23 18:11 vonWojtas

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.

JiangHongTiao avatar Nov 29 '23 17:11 JiangHongTiao

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

japzio avatar May 03 '24 21:05 japzio

https://github.com/springdoc/springdoc-openapi-gradle-plugin/pull/144 should resolve this issue.

bnasslahsen avatar Jun 22 '24 19:06 bnasslahsen