Base solution for your next web application
Open Closed

How to change SecurityStamp response message? #9054


User avatar
0
inventiskr created

I set "AllowOneConcurrentLoginPerUser" to true for not allow the duplicate login. So first token get failed checking after seconde login and client always receive 401 StatusCode, with message "Current user did not login to system". I want to modify 'UserFriendlyException' message like 'A duplicate login has been detected. Your connection to the server has been lost. Access time : 11AM / IP : 192.168.0.1'. How to change response message when duplicate login?


3 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team

    hi

    You can consider storing the information in current request/httpcontext.items or somewhere in the ValidateSecurityStampAsync method. Then rewrite AbpExceptionFilter(https://github.com/aspnetboilerplate/aspnetboilerplate/blob/dev/src/Abp.AspNetCore/AspNetCore/Mvc/ExceptionHandling/AbpExceptionFilter.cs#L73) to try to read the information you stored. And return it.

  • User Avatar
    0
    inventiskr created

    Hi,

    I tested to change 'SecurityTokenException' message following your guide. However, the method of rewrited 'AbpExceptionFilter' not execute.

    Could you share detail guide about to change 'SecurityTokenException' message. I wanna change the message of 'SecurityTokenException'

    for example, (After) { "result": null, "targetUrl": null, "success": false, "error": { "code": 0, "message": "A duplicate login has been detected.", "details": null, "validationErrors": null }, "unAuthorizedRequest": true, "__abp": true }

    (Before) { "result": null, "targetUrl": null, "success": false, "error": { "code": 0, "message": "Current user did not login to the application!", "details": null, "validationErrors": null }, "unAuthorizedRequest": true, "__abp": true }

  • User Avatar
    0
    maliming created
    Support Team

    Please refer to this issue to replcae AbpExceptionFilter

    https://github.com/aspnetboilerplate/aspnetboilerplate/pull/4215#issuecomment-456648709