[英]Why Spring Security permitAll() is not working with OAuth2.0?
[英]Swagger Codegen is not working while generating java client for a Rest API having OAuth2.0 security
我正在尝试为具有OAuth 2.0安全性的REST Api使用swagger代码生成客户端。 呼叫如下:
E:\>java -jar swagger-codegen-distribution-2.1.2-M1.jar -a access_token:df8eb092-e34f-48f9-b4ce-32cdd1ae2613 -i http://localhost:8080/someapi/api-docs -l java -o E:\projects\prototypes\ApiClient
但是此调用无法正常工作,并生成以下输出:
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
reading from http://localhost:8080/someapi/api-docs
reading from http://localhost:8080/someapi/api-docs
usage: Codegen
-a,--auth addes authorization headers when fetching the
swagger definitions remotely. Pass in a
URL-encoded string of name:header with a comma
separating multiple values
-d,--debug-info prints additional info for debugging
-h,--help shows this message
-i,--input-spec <arg> location of the swagger spec, as URL or file
-l,--lang <arg> client language to generate.
Available languages include:
[android, async-scala, java, jaxrs, nodejs,
objc, scalatra, scala, dynamic-html, html,
swagger, tizen, php, python]
-o,--output <arg> where to write the generated files
-t,--template-dir <arg> folder containing the template files
我最近已经为此API实现了OAuth2.0,因此我认为我使用此APi设置的身份验证标头存在一些问题,因为之前的代码生成很好。
我在上面的命令中为-a选项尝试了以下组合:
-a access_token:<token>
-a "access_token":<token>
-a name:AUTHORIZATION,<token>
但是没有任何效果。 我今天的演示真的很麻烦。 非常感谢任何快速帮助
谢谢
我自己一直在尝试相同的事情,因此我将发布我认为您的问题所在。 请尝试使用以下格式的命令。
java -jar <Path of codegen jar>/swagger-codegen-cli.jar generate -i <path of swagger JSON>/swagger.json -l java -o <Output path>
在您的命令中,我在“ http:// localhost:8080 / someapi / api-docs ” 中看不到JSON文件名
如果这不起作用,我要做的就是使代码生成成功进行。
安装要从源代码进行构建,您需要安装以下文件并在$ PATH中可用:
以下命令可用于从源代码构建代码生成
您也可以直接从maven.org下载JAR(最新版本)
产生程式码
您可以使用以下命令为从Swagger编辑器生成的特定JSON生成代码。
与此相关的其他详细信息可以在链接https://github.com/swagger-api/swagger-codegen/blob/master/README.md#compatibility中找到
生成的代码具有Maven构建,因此该代码的库依赖关系在pom.xml中指定。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.