所以我需要支持多租户并已在此处阅读相关内容。
我已按照以下步骤添加:身份验证管理器(假 uri):
JwtIssuerReactiveAuthenticationManagerResolver authenticationManagerResolver = new JwtIssuerReactiveAuthenticationManagerResolver
("https://jwt.com/token.json");
Run Code Online (Sandbox Code Playgroud)
使用新的 oauth2ResourceServer:
.oauth2ResourceServer(oauth2 -> oauth2.
authenticationManagerResolver(authenticationManagerResolver));
Run Code Online (Sandbox Code Playgroud)
但代码总是返回 401。当在单一租户中使用相同的 uri 时,它成功运行,所以我不确定我错过了什么。这是老方法。
yaml:
oauth2:
resourceserver:
jwt:
jwk-set-uri: https://jwt.com/token.json
Run Code Online (Sandbox Code Playgroud)
与实施:
.oauth2ResourceServer(oauth2 -> oauth2.
jwt(Customizer.withDefaults()));
Run Code Online (Sandbox Code Playgroud)
这样就认证成功了。
我也确实在日志中看到了差异。
使用身份验证解析器:
2023-03-21 11:46:11.085 DEBUG 15271 --- [ctor-http-nio-3] o.s.w.s.adapter.HttpWebHandlerAdapter : [cabda122-1] HTTP GET "/api/v1/redacted"
2023-03-21 11:46:11.136 DEBUG 15271 --- [ctor-http-nio-3] o.s.w.s.adapter.HttpWebHandlerAdapter : [cabda122-1] Completed 401 UNAUTHORIZED
Run Code Online (Sandbox Code Playgroud)
而老方式明确调用资源服务器并解码:
2023-03-21 11:41:53.843 DEBUG 12500 --- [ctor-http-nio-3] o.s.w.s.adapter.HttpWebHandlerAdapter : [963bfd7a-1] HTTP GET "/api/v1/redacted"
2023-03-21 11:41:53.932 DEBUG 12500 --- [ctor-http-nio-3] o.s.w.r.f.client.ExchangeFunctions : …Run Code Online (Sandbox Code Playgroud)