我能够启用授权按钮,但是当我单击授权按钮时,对于 oauth2 隐式流程,它会提示缺少随机数参数。
The 'nonce' parameter is required for authorize requests with either the 'id_token' or 'token' response types
这是我用来创建隐式流的代码
new OpenAPI()
.addSecurityItem(new SecurityRequirement().addList(securitySchemeName))
.components(new Components()
.addSecuritySchemes(securitySchemeName,
new SecurityScheme()
.name(securitySchemeName)
.type(SecurityScheme.Type.OAUTH2)
.description("This API uses OAuth 2 with the implicit grant flow.")
.flows(new OAuthFlows()
.implicit(new OAuthFlow()
.authorizationUrl(authorizeUri)
.scopes(new Scopes()
.addString("read", "read")))
在 Springfox 中,要添加 nonce 参数,您需要为 SecurityConfiguration 创建一个 bean,并使用 extraQueryStringsParams() 方法。
SecurityConfiguration#additionalQueryStringParams()
您可以在其中添加随机数作为键,并在值对中添加随机字符串。我尝试使用 OAuthFlows 和 SecurityScheme 上的扩展,但它似乎仍然不起作用。
我不确定我缺少什么,非常感谢任何帮助。
最佳答案
好吧,我明白了,没有添加额外查询参数的功能。您只需自己将其硬编码到字符串中,然后将其添加到 url 中。
.authorizaitonUrl(authroizeUri + "?nonce=\"asdf\"")
关于SpringDoc Oauth2 需要隐式流随机数参数且身份验证失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61652540/