swagger-api / swagger-api/swagger-codegen
Swagger codegen oAuth issue
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
The OAUTH with basic authentication sends the headers to request the token in the body instead in the authorization header with bearer.
Swagger-codegen version
The latest from Maven.
Swagger declaration file content or url
We wanted to create a swagger client for java with the feign library. The problem is, that all the variables are send within the body to request the authentication from the auth server.
While it is needed to have those in the headers.
Command line used for generation
Generated with the Maven plugin.
Steps to reproduce
Generate client with oAuth and basic auth (double auth).
Then instantiate this client and try to get the client
Suggest a fix/enhancement
Exception in thread "main" feign.RetryableException
at io.swagger.client.auth.OAuth.updateAccessToken(OAuth.java:97)
at io.swagger.client.auth.OAuth.apply(OAuth.java:83)
at feign.SynchronousMethodHandler.targetRequest(SynchronousMethodHandler.java:158)
at feign.SynchronousMethodHandler.executeAndDecode(SynchronousMethodHandler.java:88)
at feign.SynchronousMethodHandler.invoke(SynchronousMethodHandler.java:76)
at feign.ReflectiveFeign$FeignInvocationHandler.invoke(ReflectiveFeign.java:103)
at com.sun.proxy.$Proxy5.welcomeUsingGET(Unknown Source)
at com.test.Main.main(Main.java:33)
Caused by: java.lang.NullPointerException
at io.swagger.client.auth.OAuth$OAuthFeignClient.execute(OAuth.java:177)
at org.apache.oltu.oauth2.client.OAuthClient.accessToken(OAuthClient.java:65)
at org.apache.oltu.oauth2.client.OAuthClient.accessToken(OAuthClient.java:55)
at org.apache.oltu.oauth2.client.OAuthClient.accessToken(OAuthClient.java:71)
at io.swagger.client.auth.OAuth.updateAccessToken(OAuth.java:95)
... 7 more
I guess that there needs to be a template change that places the beared in the authorization header instead inside the body.
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 with the generated OAuth flow in OAuth.java, especially the updateAccessToken, apply, and OAuthFeignClient.execute locations shown in the stack trace, and inspect the Maven generation templates that produce it. Reproduce a Java Feign client with OAuth and basic authentication; done means token-request credentials use the required authorization header and the reported NullPointerException no longer occurs.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api, authentication
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100