【问题标题】:Azure Single Sign on post request giving 403 forbidden errorAzure Single Sign on post request 给出 403 禁止错误
【发布时间】:2025-12-21 09:50:10
【问题描述】:

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

azure.activedirectory.tenant-id

azure.activedirectory.client-id

azure.activedirectory.client-secret

我还添加了重定向网址 在 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...");
   
  }​​​​​
}​​​​​);

还有邮局电话

  $.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...");
       
      }​​​​​
    }​​​​​);

我不知道为什么邮局电话不起作用

【问题讨论】:

  • 服务器是否需要 csrf 令牌?
  • @sdoxsee 我没有配置任何过滤器

标签: javascript spring-boot azure spring-mvc single-sign-on


【解决方案1】:

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

在 Java 配置中默认启用 CSRF 保护。如果需要,我们仍然可以禁用它:

@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

【讨论】:

  • 我试了你的代码,post 调用成功了。让我通过您发送的链接。一旦它正常工作,我会接受这个答案
最近更新 更多