We are currently implementing a Single Page Application (Angular2) and thus have run into the standard "how do we secure our backend API" problem.
The standard solution to this apparently to use the OAuth2 Implicit Grant Flow, which is all fine. We are implementing an custom Authorization Server which authenticates using our Web SSO Solution (Open AM/SAML), checks for licenses, and then issues Access Tokens via the API Gateway (Mashape Kong).
The Access Token is (as specified in the OAuth2 Implicit Flow) passed back to the SPA using a redirect, giving the access token in the fragment (https://my.spa.com/#access_token=asdfasdf&token_type=bearer&expires_in=1800
).
So far, no specialties. Now: The access token is only valid for a short period of time, and there is no refresh token; we do not want the end user to actually be redirected to the Authorization Server again (it would look bad/flicker/...). Our idea was to use the existing session with the Authorization Server (which we implemented, see above) to refresh the access token (create a new one) via a CORS call to a special end point of the Authorization Server (let's call it /heartbeat
).
Obviously, this requires a couple of things to be done:
- The
Origin
needs to be exactly the calling application's host, and the Auth Server needs to verify and reflect that in the preflight response - The client application needs to do the CORS call with activated
withCredentials: true
(usingXMLHttpRequest
,credentials: include
for Fetch)
We did a test implementation of this, and it seems to work quite nicely, but I still want to ask you guys as experts on this: Are there (additional) attack vectors when enabling this kind of refresh? In addition to the usual suspects for the implicit grant, that is.
Best regards, Martin