spring security oauth2设置错误信息为json格式

背景:

spring security oauth2默认的错误信息返回格式是xml,如果要返回json,可以在请求头中指定'Accept: application/json'。

指定为json示例

curl -i -L -H 'Accept: application/json' --data 'client_id=0000-0003-2736-8061&client_secret=5f63d1c5-3f08-4fa5-b066-fd985ffd0df7&grant_type=authorization_code&code=Q70Y3A&redirect_uri=https://developers.google.com/oauthplayground' 'http://api.sandbox-1.orcid.org/oauth/token'

指定为xml示例

curl -i -L -H 'Accept: application/xml' --data 'client_id=0000-0003-2736-8061&client_secret=5f63d1c5-3f08-4fa5-b066-fd985ffd0df7&grant_type=authorization_code&code=Q70Y3A&redirect_uri=https://developers.google.com/oauthplayground' 'http://api.sandbox-1.orcid.org/oauth/token'

测试:

没有指定JSON:

 

指定为JSON之后:

Header 中添加Accept  application/json

 

原文地址:https://www.cnblogs.com/Edward-Wang/p/13182845.html