Azure 单一登录 post 请求给出 403 禁止错误

Azure Single Sign on post request giving 403 forbidden error

我正在开发 jsp-springboot 应用程序,我已经使用 azure 实现了 sso,它按预期工作。我已经配置

azure.activedirectory.tenant-id

azure.activedirectory.client-id

azure.activedirectory.client-secret

我也添加了重定向 url 在 application.properties 中,除了这些更改之外,我没有添加任何配置 类,我也能够成功登录 ajax GET 调用是返回 200 响应代码,但对于 POST 调用给出 403 禁止错误

获取调用样本

$.ajax({​​​​​
  type: 'GET',
  url: "/getvalue/"+productId,
  contentType: "text/plain",
  dataType: 'json',
   
  success: function (data) {​​​​​
     console.log("Success");
  }​​​​​,
  error: function (e) {​​​​​
    console.log("There was an error with your request...");
   
  }​​​​​
}​​​​​);

和 post 通话

  $.ajax({​​​​​
      type: 'POST',
      url: "/saveValue",
      data:JSON.stringify(valueObj),
      contentType: "application/json",
      success: function (data) {​​​​​
      console.log("success: ");
      }​​​​​,
      error: function (e) {​​​​​
        console.log("There was an error with your request...");
       
      }​​​​​
    }​​​​​);

我不确定为什么 post 调用不起作用

GET 上的 200 和 POST 上的 403 告诉我您仍然启用了 CSRF。

CSRF protection is enabled by default in the Java configuration. We can still disable it if we need to:

@Override
protected void configure(HttpSecurity http) throws Exception {
    http
      .csrf().disable();
}

参考:https://www.baeldung.com/spring-security-csrf#1-java-configuration

不过我不建议禁用它。你可以看看 https://docs.spring.io/spring-security/reference/5.6.0-RC1/reactive/exploits/csrf.html#webflux-csrf-configure-custom-repository