Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support HTTP Basic Auth for client generation #102

Closed
akkie opened this issue Nov 7, 2013 · 11 comments
Closed

Support HTTP Basic Auth for client generation #102

akkie opened this issue Nov 7, 2013 · 11 comments
Labels
Milestone

Comments

@akkie
Copy link
Contributor

akkie commented Nov 7, 2013

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

@jfelectron
Copy link

+1 Is any auth supported? Another person on my team was trying to use swagger-codegen with oauth and no dice their either.

@fehguy
Copy link
Contributor

fehguy commented Dec 2, 2013

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:

https://github.com/wordnik/swagger-codegen/blob/master/samples/client/petstore/java/src/main/java/com/wordnik/client/ApiInvoker.java#L32

ApiInvoker.getInstance().addDefaultHeader("Authorization", "Authorization:Basic cGFzc3dvcmQ=")

@jfelectron
Copy link

Thanks. We"ll try this.

@gchan1979
Copy link

About adding -Dheader="Authorization:Basic cGFzc3dvcmQ=", does it imply the generated API clients would have hard-coded username and password?

@fehguy
Copy link
Contributor

fehguy commented Aug 26, 2014

No, this simply applies the header during codegen

@akkie
Copy link
Contributor Author

akkie commented Aug 28, 2014

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

@fehguy fehguy added this to the v2.1.0-M1 milestone Dec 24, 2014
@fehguy fehguy added the P1 label Dec 24, 2014
@StephanBeutel
Copy link

This doen't work for me. I only get this exception:

java.io.IOException: Server returned HTTP response code: 401 for URL:

@fehguy
Copy link
Contributor

fehguy commented Jan 9, 2015

will make sure this is tested for 2.1.0-m1

@keithchong
Copy link

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?

@fehguy
Copy link
Contributor

fehguy commented Feb 18, 2016

@keithchong please open a new issue. I'm sure this is supported so perhaps a usage issue.

@keithchong
Copy link

Hi Tony, will do. I'm using v2.1.5.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants