【发布时间】:2017-01-28 07:18:07
【问题描述】:
在整合我们的 json 响应时,我尝试将 spring oauth2 json 响应更改为我们的格式。
来自
{
"error": "invalid_token",
"error_description": "Invalid access token: undefined"
}
到
{
"status" : 401,
"error_code": "invalid_token",
"description": "Invalid access token: undefined"
}
我已经调试并发现了几个可能相关的点,但我无法将所有内容放在一起。
这些是我的方法
- 回复写在这里
OAuth2ExceptionJackson2Serializer,但我不知道如何在spring中交换那个序列化器 - 我找到了
WebResponseExceptionTranslator。但据我了解,它不允许在那里设置 json 正文 - json 正文是由 DefaultOAuth2ExceptionRenderer 编写的,但我无法设置它。我只找到了如何设置
ExceptionTranslator,通过在AuthorizationServerEndpointsConfigurer中设置它。但它不允许设置渲染器 - 文档谈到设置
HttpMessageConverter,我不知道该怎么做。
长话短说,我是 Spring 新手,非常感谢有关如何修改响应的一些指导。
谢谢, 奥托
【问题讨论】:
标签: java spring spring-boot spring-oauth2