How should I handle a redirect to an identity provider during a web api data request

Posted by Erds on Programmers See other posts from Programmers or by Erds
Published on 2012-11-01T20:14:37Z Indexed on 2012/11/01 23:19 UTC
Read the original article Hit count: 245

Filed under:
|
|
|

Scenario

I have a single-page web app consisting purely of html, css, and javascript. After initial load and during use, it updates various views with data from one or more RESTful apis via ajax calls. The api calls return data in a json format. Each web api may be hosted on independent domains.

Question

During the ajax callout, if my authorization token is not deemed valid by the web api, the web api will redirect me (302) to the identity provider for that particular api. Since this is an ajax callout for data and not necessarily for display, i need to find a way to display the identity provider's authentication page. It seems that I should trap that redirect, and open up another view to display the identity provider's login page. Once the oauth series of redirects is complete, i need to grab the token and retrigger my ajax data call with the token attached.

Is this a valid approach, and if so are there any examples showing the ajax handling of the redirects?

© Programmers or respective owner

Related posts about JavaScript

Related posts about rest