java - 无法通过 Keycloak 中的 refreshToken 获取刷新 accessToken
问题描述
我可以通过 Postman 获得刷新 accessToken。但无法在 java 中使用 restTemplate 获取 accessToken。我收到了 400 错误请求。
public String fetchAccessToken(String refreshToken) throws Exception {
String url = "https://localhost:8080/auth/realms/sso/protocol/openid-connect/token";
Map<String, String> map = new HashMap<String, String>();
map.put("client_id", "keycloak-client");
map.put("grant_type", "refresh_token");
map.put("refresh_token", refreshToken);
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
HttpEntity<Map<String, String>> requestEntity = new HttpEntity<>(map, headers);
ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.POST, requestEntity, String.class);
return response.getBody();
}
解决方案
推荐阅读
- python - 如何在新的 Tkinter 窗口中显示导入的数据框?
- python - Python - 将 2 列 CSV 附加在一起
- tensorflow - 如何在 Julia 中将 TensorFlow 升级到 2.0?
- reactjs - 如何使用 jest 在 React Component 中模拟 observable
- python - 无法验证 JSON 数组中的“必需”属性
- android - 迁移到 2.17 后 Dagger 失败
- android - Flutter 构建 android-arm64 失败,android-x64 发布版本
- python - 是否可以在 python unittest (HtmlTestRunner) 中命名单个子测试?
- android - 是否可以将 Uri 留空?因为当我在没有图像的情况下单击下一步时,它会强制关闭-Kotlin
- javascript - 如何通过 Jquery 向 C# 方法发送请求并获取其参数