swagger-api / swagger-api/swagger-codegen
Java Swagger generated rest client Problem authorizing requests via the generated client.
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Hello ,
I am getting error in java client as below while using Basic Authentication in Swagger 2.0 version.
while generating client (java client) , we used swagger-codegen-cli-2.1.2.jar version.
io.swagger.client.ApiException: Authentication Required
at io.swagger.client.ApiClient.invokeAPI(ApiClient.java:445)
at io.swagger.client.api.CustomersApi.customersGet(CustomersApi.java:97)
from java level i can generate token by username:password.
token is matching between swagger UI tool and Java client.
below is the sample code
String auth = key + ":" + secret;
byte[] encodedAuth = Base64.encodeBase64(auth.getBytes(Charset.forName("US-ASCII")));
String authHeader = "Basic " + new String(encodedAuth);
System.out.println("the basic auth header value is "+authHeader);
i am not sure how to pass this token in request header.
kindly help me , how to attach generated token in request header by using Generated Java Client API Classes?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading the generated client flow in ApiClient.java around invokeAPI and the call from CustomersApi.java. Reproduce the Basic Authentication request with swagger-codegen-cli-2.1.2.jar and compare it with the working Swagger UI request. Done means the generated Java client sends the expected authorization header and the request no longer returns Authentication Required.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi
- Domain
- api, authentication
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100