angularjs - 使用 Apache 捕获 302 并返回 401

标签 angularjs ajax apache http shibboleth

我们目前有一个保护特定路径的 shibboleth 实现。然而,因为这个路径实际上是一个 HTTP 请求(使用 $http 由 AngularJS 应用程序发出),shibboleth 将尝试将这个请求“重定向”到身份提供者,但浏览器只是将其解释为无效请求。它以 status=-1 且没有关联的 header /数据返回给 AngularJS。

我想拦截这个 302 而不是返回 401,最好能够编辑响应 header 。有没有什么方法可以使用 Apache 或 Shibboleth 来做到这一点?

相关 block :

# Proxy all requests to WebLogic
<Location "/api">
    SetHandler weblogic-handler
    WLSRequest On
    WebLogicHost services.endpoint.com
    WebLogicPort 9002
</Location>

# For requests marked as protected, apply shibboleth
# If this block gets triggered, Shibboleth attempts redirect
# which does not work with our architecture
<Location "/api/protected">
     AuthType Shibboleth
     ShibRequireSession On
     ShibApplicationId default
     ShibExportAssertion On
     Require Shibboleth
</Location>

它在 AngularJS 中的使用方式:

//API call to unprotected endpoint
$http.get('http://hosted.on.apache.com/api/getData');

//API call to protected endpoint - Shibboleth triggered
$http.get('http://hosted.on.apache.com/api/protected/getSecureData');

最佳答案

我不熟悉 Sibboleth,但正如人们在评论中指出的那样,这可以通过反向代理轻松实现。

请参阅此答案中建议的解决方案作为引用:

Apache - Reverse Proxy and HTTP 302 status message

关于angularjs - 使用 Apache 捕获 302 并返回 401,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38135027/

相关文章:

javascript - 使用诱饵会破坏我在 IE 上的上传。为什么?

jquery - 无效的 ajax 内容

php - php文件中的8个空格如何使apache崩溃?

apache - 如何仅在 HTTPS 上从 .htaccess 设置 HSTS header

javascript - 从类方法中的 ajax post 函数回调函数更改 javascript 类属性

python - 在 Ubuntu 14.04 上使用 Apache2 和 mod_wsgi 服务 Django 1.8 应用程序时出错

javascript - 工厂内的$watch

javascript - daterangepicker 在引导模式弹出窗口中不起作用

javascript - 在同一 Controller 内测试 Angular modalInstance

javascript - AngularJS HTTP POST 不发送数据