Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将客户端id添加到Spring Boot OAuth Security为Twitch执行的请求中_Spring_Spring Security_Oauth - Fatal编程技术网

如何将客户端id添加到Spring Boot OAuth Security为Twitch执行的请求中

如何将客户端id添加到Spring Boot OAuth Security为Twitch执行的请求中,spring,spring-security,oauth,Spring,Spring Security,Oauth,我正在使用SpringSecurityOAuth。Spring能够成功地为访问令牌交换身份验证 但是,对于随后访问受保护的资源,Twitch还要求在访问受保护的资源时传递客户端\u id,Spring似乎只传递访问\u令牌 我尝试更新模板,但这似乎也没有将它们作为其他URI参数传递: OAuth2RestTemplate template = new OAuth2RestTemplate(client.getClient(), oauth2ClientContext()); HashMap ma

我正在使用SpringSecurityOAuth。Spring能够成功地为访问令牌交换身份验证

但是,对于随后访问受保护的资源,Twitch还要求在访问受保护的资源时传递客户端\u id,Spring似乎只传递访问\u令牌

我尝试更新模板,但这似乎也没有将它们作为其他URI参数传递:

OAuth2RestTemplate template = new OAuth2RestTemplate(client.getClient(), oauth2ClientContext());
HashMap map = new HashMap();
map.put("client_id", "MY_CLIENT_SECRET");
template.setDefaultUriVariables(map);
filter.setRestTemplate(template);
同样,这似乎也不起作用


如何让Spring的OAuth2也传递客户端id?

我通过创建自定义UserInfoTokenService并重写getMap(字符串路径、字符串访问令牌)解决了这个问题:

MultiValueMap headers=新链接的MultiValueMap();
DefaultOAuth2AccessToken=新的DefaultOAuth2AccessToken(
accessToken);
headers.add(“Authorization”,String.format(“%s%s”,“OAuth”,accessToken));
logger.info(String.format(“%s%s”,“OAuth”,accessToken));
添加(“内容类型”、“应用程序/json”);
HttpEntity he=新的HttpEntity(空,标题);
ResponseEntity exchange=restemplate.exchange(路径,HttpMethod.GET,he,
地图(类别),;
返回exchange.getBody();
        MultiValueMap<String, String> headers = new LinkedMultiValueMap<>();
        DefaultOAuth2AccessToken token = new DefaultOAuth2AccessToken(
                accessToken);
        headers.add("Authorization", String.format("%s %s", "OAuth", accessToken));
        logger.info(String.format("%s %s", "OAuth", accessToken));
        headers.add("Content-Type", "application/json");
        HttpEntity he = new HttpEntity(null, headers);
        ResponseEntity<Map> exchange = restTemplate.exchange(path, HttpMethod.GET, he,
                Map.class);
        return exchange.getBody();