swagger-api / swagger-api/swagger-codegen

Unable to call a restful service using swagger codegen and saying unauthorized for basic auth

Open
#5,743 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Hi Team,

Consuming a restful service using swagger codegen 2.0 But its failing the authentication.

"swagger": "2.0",
"info": {
"version": "2.1.0",
"title": "GeoES"

Schema does not have securityDefinitions:
basic:
type: basic
description: HTTP Basic Authentication.

So, I tried changing Apiclient authantications map and added manually credentials. But no luck.
HttpBasicAuth hba= new HttpBasicAuth();

	    hba.setUsername("*******");
        hba.setPassword("*******");
        authentications.put("basic", hba);
   authentications = Collections.unmodifiableMap(authentications);

I changed buildCall to allow but still It's not getting authenticated. Need Help !!
String authNames2[] = {"basic"};
updateParamsForAuth(authNames2, queryParams, headerParams);

Thank you

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Swagger 2.0 definition and the generated Java ApiClient, focusing on buildCall and updateParamsForAuth. Reproduce the request with basic authentication configured, then verify that the generated call sends credentials and no longer receives an unauthorized response.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api, authentication
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.