SpringDoc Oauth2 需要隐式流现时参数且身份验证失败
SpringDoc Oauth2 Implicit flow nonce parameter required and auth fails
我可以启用授权按钮,但是当我点击授权按钮时,对于 oauth2 隐式流,它会抱怨缺少 nonce 参数。
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 并使用 additionalQueryStringsParams() 方法。
SecurityConfiguration#additionalQueryStringParams()
您可以在其中添加随机数作为键,并在值对中添加一个随机字符串。我尝试在 OAuthFlows 和 SecurityScheme 上使用扩展,但它似乎仍然无法正常工作。
我不确定我错过了什么,感谢任何帮助。
好的,我明白了,没有添加额外查询参数的功能。您只需要自己将其硬编码到字符串中,然后将其添加到 url.
.authorizaitonUrl(authroizeUri + "?nonce=\"asdf\"")
我可以启用授权按钮,但是当我点击授权按钮时,对于 oauth2 隐式流,它会抱怨缺少 nonce 参数。
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 并使用 additionalQueryStringsParams() 方法。
SecurityConfiguration#additionalQueryStringParams()
您可以在其中添加随机数作为键,并在值对中添加一个随机字符串。我尝试在 OAuthFlows 和 SecurityScheme 上使用扩展,但它似乎仍然无法正常工作。
我不确定我错过了什么,感谢任何帮助。
好的,我明白了,没有添加额外查询参数的功能。您只需要自己将其硬编码到字符串中,然后将其添加到 url.
.authorizaitonUrl(authroizeUri + "?nonce=\"asdf\"")