What method should I use for a login (authentication) request?

后端 未结 6 808
天涯浪人
天涯浪人 2020-12-23 10:41

I would like to know which http method I should use when doing a login request, and why? Since this request creates an object (a user session) on the server, I think it shou

6条回答
  •  萌比男神i
    2020-12-23 11:29

    Regarding the method for logging out:

    In the Spring (Java Framework) documentation, they state that a POST request is preferred, since a GET makes you vulnerable to CSRF (Cross-Site Request Forgery) and the user could be logged out.

    Adding CSRF will update the LogoutFilter to only use HTTP POST. This ensures that log out requires a CSRF token and that a malicious user cannot forcibly log out your users.

    See: https://docs.spring.io/spring-security/site/docs/current/reference/html/web-app-security.html#csrf-logout

    Logging in should also use POST (body can be encrypted, see the other answers).

提交回复
热议问题