Spring Cloud Gateway OAuth2 with Spring Security OAuth2 Authorization Server = loop
Spring Cloud Gateway OAuth2 with Spring Security OAuth2 Authorization Server = loop
我正在尝试将 Spring 授权服务器与 Spring 云网关一起使用,但我无法获取用户信息。我可以在网关日志中看到类似
的消息
[2020-03-23 13:36:35,061] TRACE org.springframework.web.HttpLogging - [45961b04] Decoded [{access_token=5b5a13f1-2b47-4739-bda2-74785f6e3828, token_type=bearer, expires_in=33556, scope=read}]
这意味着授权工作正常,但在 302 FOUND Location: /res (protected resource) 之后它会将我转发回授权服务器。
完整代码在此处的演示项目中:https://github.com/looksworking/gw-oauth
授权服务器:
Spring 云网关:
非常感谢任何帮助。
网关无法从授权服务器获取用户信息来创建主体。因此,由于缺少主体,它再次重定向到授权服务器。尝试在授权服务器中创建自定义用户信息端点。 (/userinfo 而不是 /oauth/userinfo)。您可能需要在安全配置中允许 /userinfo。
@RestController
public class UserInfoEndpoint {
@PostMapping("/userinfo")
public Map<String, Object> user() {
Map<String, Object> map = new HashMap<>();
String name = SecurityContextHolder.getContext().getAuthentication().getName();
map.put("user_name", name);
return map;
}
}
此外,将 user-info-authentication-method: form 添加到您的提供商。
我正在尝试将 Spring 授权服务器与 Spring 云网关一起使用,但我无法获取用户信息。我可以在网关日志中看到类似
的消息[2020-03-23 13:36:35,061] TRACE org.springframework.web.HttpLogging - [45961b04] Decoded [{access_token=5b5a13f1-2b47-4739-bda2-74785f6e3828, token_type=bearer, expires_in=33556, scope=read}]
这意味着授权工作正常,但在 302 FOUND Location: /res (protected resource) 之后它会将我转发回授权服务器。
完整代码在此处的演示项目中:https://github.com/looksworking/gw-oauth
授权服务器:
Spring 云网关:
非常感谢任何帮助。
网关无法从授权服务器获取用户信息来创建主体。因此,由于缺少主体,它再次重定向到授权服务器。尝试在授权服务器中创建自定义用户信息端点。 (/userinfo 而不是 /oauth/userinfo)。您可能需要在安全配置中允许 /userinfo。
@RestController
public class UserInfoEndpoint {
@PostMapping("/userinfo")
public Map<String, Object> user() {
Map<String, Object> map = new HashMap<>();
String name = SecurityContextHolder.getContext().getAuthentication().getName();
map.put("user_name", name);
return map;
}
}
此外,将 user-info-authentication-method: form 添加到您的提供商。