伪装OAuth2 OAuth /令牌春季启动

时间:2018-08-17 06:43:31

标签: oauth-2.0 spring-security-oauth2 spring-oauth2 feign

我正在尝试通过伪客户端端口而不是oauth服务器端口屏蔽oauth /令牌生成。我已经添加了请求拦截器。

但是当我尝试生成令牌时,得到的406不可接受,如下所示:

But when I'm trying to generate token I'm getting 406 not acceptable

有人可以发布解决方案吗?

public class UserFeignClientInterceptor implements RequestInterceptor {
    private static final String AUTHORIZATION_HEADER = "Authorization";
    private static final String BEARER_TOKEN_TYPE = "Bearer";

    @Override
    public void apply(RequestTemplate template) {
        SecurityContext securityContext = SecurityContextHolder.getContext();
        Authentication authentication = securityContext.getAuthentication();

        if (authentication != null && authentication.getDetails() instanceof OAuth2AuthenticationDetails) {
            OAuth2AuthenticationDetails details = (OAuth2AuthenticationDetails) authentication.getDetails();
            System.out.println("details " + details.getRemoteAddress());
            System.out.println("details " + details.getSessionId());
            System.out.println("details " + details.getTokenType());
            System.out.println("details " + details.getTokenValue());
            System.out.println("details " + details.getDecodedDetails());
            template.header(AUTHORIZATION_HEADER, String.format("%s %s", BEARER_TOKEN_TYPE, details.getTokenValue()));
        }
    }
}

0 个答案:

没有答案