使用 Grails 3.3.5 和 Spring-security-rest 2.0.0-RC1 处理 REST API 应用程序。
当我使用 /api/login 登录时,我得到了正确的结果:
{
"username": "name.surname@acme.com",
"roles": [
"ROLE_USER"
],
"access_token": "qgsbpk05jfrbf33xx08m8r4govkg53d1"
}
我想在响应中添加其他信息,例如用户的姓名和姓氏。谢谢
更新 感谢 Evgeny 为我指明了正确的方向并阅读了我还实现了 UserDetailsService 的手册。从手册:
如果要在 JSON 响应中呈现附加信息,则必须:
Configure an alternative userDetailsService bean that retrieves the additional information you want, and put it in a principal object. Configure an alternative accessTokenJsonRenderer that reads that information from the restAuthenticationToken.principal object.