密钥斗篷重定向到令牌端点



我正在使用keycapture的端点,我使用OAuth资源服务器,我想使用http://localhost:port/auth/realms/myrealm/protocol/openid-connect/token来获取令牌,但我不知道如何从我的spring端点重定向到keycapture端点

这是我的试用版,但它不起作用

public LoginData login(@RequestBody LoginData logindata){
MultiValueMap<String, String> headers = new LinkedMultiValueMap<String, String>();
Map map = new HashMap<String, String>();
map.put("Content-Type", "application/x-www-form-urlencoded");
headers.setAll(map);
HttpEntity<LoginData> entity = new HttpEntity<LoginData>(logindata,headers);
RestTemplate restTemplate = new RestTemplate();
ResponseEntity<LoginData> response = restTemplate.exchange(
"http://localhost:port/auth/realms/myrealm/protocol/openid-connect/token", HttpMethod.POST, entity, LoginData.class);
System.out.println(response);
return response.getBody();
}

为什么需要调用这个端点。只需与Spring security oauth2客户端库集成即可

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-oauth2-client</artifactId>
</dependency>

或者,如果你想与专有的Keycloft库集成,请使用弹簧的Keyclock适配器

对于spring-oauth2,您将需要使用其他配置,如spring.security.oauth2.client.registration
spring.security.oauth2.client.provider.keycloft
这不是一个完整的答案,只是一个方向

最新更新