After developing a REST Web API application, I want to provide other developers with the capability to access those APIs on behalf of the user. To achieve this, I have implemented OAuth authentication with IdentityServer3. Currently, I have successfully generated an Access Token for a third-party client using Authorization Flow.
However, I am facing a challenge with my Single Page Application (SPA) that currently uses cookie-based authentication along with an anti-forgery token to call my Web API. The SPA is built on Javascript with Backbone and its main function is to fetch data from the Web API and display the results. I am unsure about how to handle different grant flows without compromising security.
Here are a couple of solutions I have considered:
- Generating a token directly through JavaScript. Which flow would be appropriate for this? How should token refresh be managed?
- Generating a token from a backend server application and passing it to the SPA securely through an SSL channel. Is this method secure? If so, which flow should be used (perhaps Authorization Code Flow)? How to handle token refresh in this case?
I would appreciate any input on how to approach this situation effectively. Thank you.
Best regards,
Marco