It isn't possible to create a client if the API is protected with HTTP Basic Auth.
It should be possible to pass the credentials in the URL. Maybe like:
http://user:password@host/api-docs special-key
+1 Is any auth supported? Another person on my team was trying to use swagger-codegen with oauth and no dice their either.
You can pass headers when running the codegen with the following system property:
-Dheader="key:value"
So for the password "password", you could simply run btoa("password") to get the basic auth password, and pass it as a header:
-Dheader="Authorization:Basic cGFzc3dvcmQ="
That will let you pass any header (including basic auth) to the codegen.
When actually using the client, I believe all libraries support passing headers. For example in java:
ApiInvoker.getInstance().addDefaultHeader("Authorization", "Authorization:Basic cGFzc3dvcmQ=")
Thanks. We"ll try this.
About adding -Dheader="Authorization:Basic cGFzc3dvcmQ=", does it imply the generated API clients would have hard-coded username and password?
No, this simply applies the header during codegen
Adding -Dheader="Authorization:Basic cGFzc3dvcmQ=" doesn't work, because of the space inside the string.
$ bin/php-payment.sh -Dheader="Authorization:Basic cGFzc3dvcmQ="
No such file or class on classpath: cGFzc3dvcmQ=
@see https://www.google.de/?gws_rd=ssl#q=JAVA_OPTS+spaces
This doen't work for me. I only get this exception:
java.io.IOException: Server returned HTTP response code: 401 for URL:
will make sure this is tested for 2.1.0-m1
Hello, I am still getting a Server returned HTTP response code: 401 for URL when I try to generate the java client code. Do you need to provide -auth?
@keithchong please open a new issue. I'm sure this is supported so perhaps a usage issue.
Hi Tony, will do. I'm using v2.1.5.