更改错误凭据错误响应 spring security oauth2 [英] Change the Bad credentials error response spring security oauth2

查看:50
本文介绍了更改错误凭据错误响应 spring security oauth2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 AuthorizationServer,它使用 spring security 使用密码 grant_type.我将此用于移动应用程序,当用户输入用户名密码登录时,如果他/她是经过身份验证的用户,应用程序将调用令牌端点并生成令牌.这一切都由密码 grant_type 本身处理.对于不成功的登录,它会返回以下带有 400 HTTP 状态代码的一般错误.

I have a AuthorizationServer which uses password grant_type using spring security. I am using this for mobile application, when a user enter username password to log in, the app calls the token endpoint and generate a token if he/she is an authenticated user. This is all handled by password grant_type itself. For a unsuccessful log in it returns below general error with 400 HTTP status code.

{
  "error": "invalid_grant",
  "error_description": "Bad credentials"
}

但对于我的场景,我需要自定义此错误消息.他们是否可以更改此错误消息?

But for my scenario I need customize this error message. Is their a way to change this error message ?

请注意,我尝试了建议的重复问题 -使用 AuthenticationFailureHandler 在 Spring Security 中自定义身份验证失败响应但它使用了 formLogin 并且它不适用于我的实现.

Note that i tried the suggested duplicate question - Customize authentication failure response in Spring Security using AuthenticationFailureHandler but it uses the formLogin and it's not working with my implementation.

谢谢,

拉吉特

推荐答案

我好几天都找不到这个问题的答案.最后,我得到了一位同事的帮助.他让我按照这个教程为我工作.现在我可以将默认的 spring 框架响应转换为我的响应模板,如下所示.

I couldn't find an answer to this problem for many days. Finally, I got help from one of my colleagues. He asked me to follow this tutorial and it worked for me. Now I could transform the default spring framework response to my response template as follows.

{
    "status": 400,
    "message": "Invalid username or password",
    "timestamp": "2020-06-19T10:58:29.973+00:00",
    "payload": null
 }

但是,我们仍然不知道为什么 authenticationFailure 处理程序不起作用.希望这会有所帮助.

But still, we don't know, why authenticationFailure handler is not working. Hope this helps.

这篇关于更改错误凭据错误响应 spring security oauth2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆