angularjs - Shibboleth SSO CORS 错误

标签 angularjs single-sign-on shibboleth

我们的应用程序(AngularJS + REST)受 Shibboleth 服务提供商的 SSO 保护。 问题是我们在尝试对 REST 服务进行 ajax 调用时看到 CORS 错误,称重定向到 IDP 失败“跨源请求被阻止:同源策略不允许读取远程资源”

但是,如果我们刷新/重新加载浏览器,一切都会正常。我相信cookie不是第一次创建的,而是在强制重新加载后创建的。

显然,这种每次都刷新浏览器的解决方案是 Not Acceptable 。

需要做什么才能使这项工作无需重新加载?

感谢您提前提供的任何指示。

最佳答案

我自己正在处理这个问题。我不相信 Shibboleth IDP 中有任何 CORS 支持,我要使用的解决方案是来自客户端的主动保持事件 ping:

  • 定期向 Shibboleth auth session 下的某个位置发出 Ajax 请求,以防止 session 超时(例如使用 setTimeout)
  • 如果此请求失败,则会抛出整页错误,提示用户使用 something like this 重新加载页面。

只要浏览器选项卡打开并且客户端计算机处于唤醒状态,这将至少在 session "lifetime" 内防止此类 XHR 错误。 :

lifetime(time in seconds) (default is 28800) Maximum duration in seconds that a session maintained by the SP will be valid. The actual time may be less than this value (if an IdP indicates it should be shorter) but will never be longer. Note that this will not influence sessions maintained by an application.

如果客户端计算机进入休眠状态并且错过了足够多的 ping,或者如果 SP 的 session 存储被清除,他们将立即收到全屏错误,并重新加载到重新验证或重新建立其 Shibboleth session 。

我认为这是我们在 IDP 中没有 CORS 时能做的最好的事情!


这是最终对我有用的 Apache 配置,以防其他人登陆这里:

RewriteEngine On

<Location />
    AuthType Shibboleth
    ShibUseHeaders On
    ShibRequireSession On
    Require valid-user
    AuthGroupFile /etc/httpd/groups
</Location>

RewriteCond "%{LA-F:REMOTE_USER}" =""
RewriteRule ^/session-ping$ /yoursessiondoesnotexist [PT,L]

<Location /yoursessiondoesnotexist>
    AuthType None
    Require all granted
</Location>

RewriteCond "%{LA-F:REMOTE_USER}" !=""
RewriteRule ^/session-ping$ /ok.html [PT,L]

Alias /ok.html /var/www/ok.html

SetEnvIf Request_URI "^/session-ping$" DONTLOG

CustomLog /dev/stdout ncgl env=!DONTLOG

我每五秒用 XHR 轮询一次/session-ping,并在收到非 200 状态代码时抛出“您的 session 已过期”模式/调光器。

关于angularjs - Shibboleth SSO CORS 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32979785/

相关文章:

security - OpenID Connect 最终会取代 SAML 成为 SSO 的主导协议(protocol)吗?

java - 签名作为身份验证请求中的参数

Angularjs如何在 Controller 中获得常量

javascript - 将 $scope 放在 Cytoscape 点击事件中

javascript - Angular Directive(指令) - 要求包含?

node.js - 如何设置本地测试 SAML2.0 Identity Provider?

python - 如何在 python/django 中接收和验证 WS-Federation token ?

angularjs - ui-router : named views (multiple) views, 保持一切分离?

restful-authentication - Shibboleth Restful api

javascript - 如何在 AngularJS 应用程序中访问 Shibboleth SP 属性