Reputation: 2703
We're building a web application that handles user join applications, and are considering a few options around client-server versus SPA type applications. Our preference from a user experience perspective is probably fully client-side SPA, but I have API security concerns.
Because we're not authentication users (they're not users yet), the OAuth standard would imply we would need to use the "client credentials" grant type. This is not a problem if the server handles this, but in an SPA the credentials themselves are sitting in the browser for anyone to see, and our API gateway could not distinguish between a legitimate API call from our SPA in the browser versus a script someone has written with the harvested details.
A server side application could hide the client credentials and at least make sure that a) API calls require an active session (using cookies), and b) we can limit the number of certain API calls to just one per session. The server could call our API gateway with its own private credentials having done a few checks.
On the other hand with a Single Page Application running in the browser about the only controls I can think of are to do rate limiting on API calls in the API gateway, but I suspect this will achieve very little.
Random thought: One idea I had was to use "implicit" OAuth grant type as if it was a user authentication process. When we redirect to the "login" page, it actually requires no user interaction and instead grabs a fingerprint of the device (e.g. IP address, browser, language, screen resolution) then redirects back as a "successful" login. Then the client has a unique access token and we've tracked a few details about the end user for audit purposes, and potentially risk evaluation. This requires customisation of our Auth Server - certainly possible but not necessarily ideal.
Are there any other approaches people have taken to protecting API calls in SPA web apps which are successful and secure? Or am I stuck with routing API calls through the app server which applies browser-based controls?
Appreciate any thoughts or insights...
Upvotes: 5
Views: 1501
Reputation: 2703
If anybody cares - and judging from the number of views, possibly not! :) - the approach we're taking is as follows:
Where possible:
Where it's not possible to dynamically insert the access token into the JavaScript:
I decided against the tricky redirection-with-fingerprinting option as far too complex for our needs, but others might want to pursue if the approaches above don't work.
Hope someone finds this useful.
Upvotes: 4