在 Spring 安全性中@EnableOAuth2Sso 后出现错误 403
Error 403 after @EnableOAuth2Sso in Spring security
我有自己的映射 setCred/
,当通过 http POST
请求它时 returns 出现 403 错误。但是当我删除 @EnableOAuth2Sso
时,一切正常。
我不知道我在这里遗漏了什么部分。
@EnableOAuth2Sso
@Controller
public class TestAPI {
@RequestMapping(value = "/setCred", method = RequestMethod.POST, consumes = "application/json", produces = "text/plain")
public ResponseEntity<?> setCred(@RequestBody StringToken json) throws JsonParseException, JsonMappingException, IOException {
ResponseEntity<?> res = null;
....
我的最终目标是在我的网页上添加一个 facebook login
(来自 https://spring.io/guides/tutorials/spring-boot-oauth2/)
我的 application.properties
中也有 security.basic.enabled=false
protected void configure(HttpSecurity http) throws Exception {
http.csrf().disable();
}
从 Spring 开始,安全 4.0 CSRF 保护默认启用,我暂时删除了它,当时我的前端不处理任何 CSRF 令牌。但将来我会确保在每个 POST 请求中包含一个 CSRF 令牌。当然,取决于个人的意图,CSRF
可能启用或不启用,关于启用 CSRF
的唯一 "bad" 部分是增加我们代码的复杂性。
我有自己的映射 setCred/
,当通过 http POST
请求它时 returns 出现 403 错误。但是当我删除 @EnableOAuth2Sso
时,一切正常。
我不知道我在这里遗漏了什么部分。
@EnableOAuth2Sso
@Controller
public class TestAPI {
@RequestMapping(value = "/setCred", method = RequestMethod.POST, consumes = "application/json", produces = "text/plain")
public ResponseEntity<?> setCred(@RequestBody StringToken json) throws JsonParseException, JsonMappingException, IOException {
ResponseEntity<?> res = null;
....
我的最终目标是在我的网页上添加一个 facebook login
(来自 https://spring.io/guides/tutorials/spring-boot-oauth2/)
我的 application.properties
security.basic.enabled=false
protected void configure(HttpSecurity http) throws Exception {
http.csrf().disable();
}
从 Spring 开始,安全 4.0 CSRF 保护默认启用,我暂时删除了它,当时我的前端不处理任何 CSRF 令牌。但将来我会确保在每个 POST 请求中包含一个 CSRF 令牌。当然,取决于个人的意图,CSRF
可能启用或不启用,关于启用 CSRF
的唯一 "bad" 部分是增加我们代码的复杂性。