# 401 Unauthorized on POST endpoint in Spring Boot (MVC) application

**URL:** <https://community.auth0.com/t/401-unauthorized-on-post-endpoint-in-spring-boot-mvc-application/103716>\
**Category:** Get Help\
**Tags:** other, community-topic\
**Created:** [March 30, 2023, 8:16am UTC](https://community.auth0.com/t/401-unauthorized-on-post-endpoint-in-spring-boot-mvc-application/103716 "2023-03-30T08:16:57Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![ashishrky](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ashishrky/32/45827_2.png) [@ashishrky](https://community.auth0.com/u/ashishrky)\
**Post date:** [March 30, 2023, 8:16am UTC](https://community.auth0.com/t/401-unauthorized-on-post-endpoint-in-spring-boot-mvc-application/103716/1 "2023-03-30T08:16:57Z")

</div>

Hi, I am using Spring Boot 3 and Spring Security 6 and following the sample [auth0-spring-security5-api-sample/01-Authorization-MVC at use-spring-6 · auth0-samples/auth0-spring-security5-api-sample · GitHub](https://github.com/auth0-samples/auth0-spring-security5-api-sample/tree/use-spring-6/01-Authorization-MVC). Tutorial works well until try with GET endpoints. But the moment I built a POST endpoint and call it, I get 401 Unauthorized error in postman even though this is configured to be permitted in SecurityConfig.java. Here is the link to my code changes [POST Endpoint to test · ashishrky/auth0-spring-security5-api-sample@8bf9866 · GitHub](https://github.com/ashishrky/auth0-spring-security5-api-sample/commit/8bf9866a7a18fb9d2e0c78f1950725f2f42eaee2). What’s wrong? Why GET call work just fine, but POST call get 401?

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [March 30, 2023, 10:59am UTC](https://community.auth0.com/t/401-unauthorized-on-post-endpoint-in-spring-boot-mvc-application/103716/2 "2023-03-30T10:59:01Z")

</div>

Hey there!

In order to handle that most effectively can I ask you to raise it as a GitHub issue here in the repo so we can discuss that directly with the repo maintainers? Once you have a link to it you can share it here so we can ping them. Thank you!

> **[Issues · auth0-samples/auth0-spring-security5-api-sample](https://github.com/auth0-samples/auth0-spring-security5-api-sample/issues)**
>
> Sample demonstrating how to secure your API using Spring Boot 2 and Spring Security 5 - Issues · auth0-samples/auth0-spring-security5-api-sample

---

<div class="post-metadata">

**Author:** ![ashishrky](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ashishrky/32/45827_2.png) [@ashishrky](https://community.auth0.com/u/ashishrky)\
**Post date:** [March 30, 2023, 2:20pm UTC](https://community.auth0.com/t/401-unauthorized-on-post-endpoint-in-spring-boot-mvc-application/103716/3 "2023-03-30T14:20:57Z")

</div>

Hi @konrad.sopala, I have opened a github issue at… [401 Unauthorized on POST endpoint in Spring Boot (MVC) application · Issue #26 · auth0-samples/auth0-spring-security5-api-sample · GitHub](https://github.com/auth0-samples/auth0-spring-security5-api-sample/issues/26). Thanks

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [March 30, 2023, 2:21pm UTC](https://community.auth0.com/t/401-unauthorized-on-post-endpoint-in-spring-boot-mvc-application/103716/4 "2023-03-30T14:21:49Z")

</div>

Perfect! I’ll ping the repo maintainers in a few minutes!

---

<div class="post-metadata">

**Author:** ![ashishrky](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ashishrky/32/45827_2.png) [@ashishrky](https://community.auth0.com/u/ashishrky)\
**Post date:** [April 11, 2023, 4:40am UTC](https://community.auth0.com/t/401-unauthorized-on-post-endpoint-in-spring-boot-mvc-application/103716/5 "2023-04-11T04:40:10Z")

</div>

Hi @konrad.sopala, did you reach out to repo maintainers? I do not see any update on this issue. This issue is blocking usage of auth0 in my project. Can you please help? Thanks.

---

<div class="post-metadata">

**Author:** ![dawid.matuszczyk](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dawid.matuszczyk/32/74550_2.png) [@dawid.matuszczyk](https://community.auth0.com/u/dawid.matuszczyk)\
**Post date:** [May 16, 2024, 5:47pm UTC](https://community.auth0.com/t/401-unauthorized-on-post-endpoint-in-spring-boot-mvc-application/103716/6 "2024-05-16T17:47:35Z")

</div>

Reposting solution from the team shared in the github issue:

> If you turn up the logging for Spring Security in `application.yml`:
> 
> logging: level: org.springframework.security.web: DEBUG
> 
> You’ll see the error when you try to do a POST:
> 
> ```auto
> 2023-04-20T10:24:21.166-06:00 DEBUG 15786 --- [nio-3010-exec-1] o.s.security.web.FilterChainProxy : Securing POST /api/public/post
> 2023-04-20T10:24:21.184-06:00 DEBUG 15786 --- [nio-3010-exec-1] o.s.security.web.csrf.CsrfFilter : Invalid CSRF token found for http://localhost:3010/api/public/post
> 2023-04-20T10:24:21.184-06:00 DEBUG 15786 --- [nio-3010-exec-1] o.s.s.w.access.AccessDeniedHandlerImpl : Responding with 403 status code
> 2023-04-20T10:24:21.186-06:00 DEBUG 15786 --- [nio-3010-exec-1] o.s.security.web.FilterChainProxy : Securing POST /error
> 2023-04-20T10:24:21.189-06:00 DEBUG 15786 --- [nio-3010-exec-1] o.s.s.w.a.AnonymousAuthenticationFilter : Set SecurityContextHolder to anonymous SecurityContext
> 
> ```
> 
> If you disable CSRF in `SecurityConfig.java`, everything will work:
> 
> `http.csrf().disable();`
> 
> Here’s proof:

 ![](https://global.discourse-cdn.com/auth0/original/3X/7/6/76173a3a74bcfd47d787e0df1c49c91ebbcd6361.jpeg)

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [May 30, 2024, 5:47pm UTC](https://community.auth0.com/t/401-unauthorized-on-post-endpoint-in-spring-boot-mvc-application/103716/7 "2024-05-30T17:47:43Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
