weixin_33726318 2015-01-21 08:29 采纳率: 0%
浏览 120

使用SSO:Ajax请求

I have a web application and API Server, the web application consumes API always via AJAX except in a couple of scenarios.

When I enable SSO for both, I face the well known problem - how to handle redirect in AJAX.

(A bit more details: Azure mandates that the user should login to AD only via its login page - so ideally when a webpage or an api endpoint is accessed, they should get redirected to the azure login page. Since HTTP302 redirect doesn't work well with XmlHTTP, user will not get redirected to the authentication page when API is accessed via AJAX)

I have a few options to solve this issue:

  1. When the web application is authenticated redirect to a predefined api endpoint (eg: 'api/login') and that will take care of api authentication and once that is done, redirect it back to the web app. So the user will be redirected this way:

    web -> azure login -> web -> api -> azure login (auto login) -> api -> web

  2. Load the api endpoint in an iframe (or an image) and wait for the load complete event

  3. Authenticate only web application - Remove api from sso context and find some other of way to identify and validate the web request at API side (tokens, cookies)

Please help me to choose a right pattern.

  • 写回答

1条回答 默认 最新

  • DragonWar% 2015-01-21 13:13
    关注

    AJAX follows redirects automatically:

    You need to distinguish between the reply from the service and the login page, which you get after AJAX follows the redirect (but not with safari+cors!). For example, detection could be done by checking for a string inside of response body. When detected, just redirect user to the login page by document.location=<login-page-url>.

    Another option would be to use a token inside of "Authorization" HTTP header instead of SSO for backend-service protection: https://auth0.com/blog/2014/01/07/angularjs-authentication-with-cookies-vs-token/

    评论

报告相同问题?

悬赏问题

  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)
  • ¥20 matlab yalmip kkt 双层优化问题
  • ¥15 如何在3D高斯飞溅的渲染的场景中获得一个可控的旋转物体
  • ¥88 实在没有想法,需要个思路
  • ¥15 MATLAB报错输入参数太多
  • ¥15 python中合并修改日期相同的CSV文件并按照修改日期的名字命名文件
  • ¥15 有赏,i卡绘世画不出