In our web application (ASP.NET), we use OpenID Connect with the authorization code flow:
- The user is redirected to the identity provider (e.g. Azure AD), authenticates,
- The authorization code is POSTed back to a page in our web application.
- Our web app then retrieves the refresh token, id token and access token from the identity server using the authorization code. These are stored on the clients as cookies (with the HttpOnly flag set to true). This is in order to avoid a dependency on the server's state, in case the user is routed to a different web server by the load balancer.
- When the user accesses a page, we validate the ID token's signature and validity period, and checking the claim we use for the identity (e.g. email address or UPN) against the user database in our application.
This works -- except that we're unable to refresh the ID token, so users are timed out after 1 hour, requiring a new login. According to the OpenID Connect specs, when refreshing tokens with the token endpoint, not all OpenID Connect providers will supply a new ID token.
The alternatives we see so far:
- Don't use the ID token at all. Use the access token to query the UserInfo endpoint for the user's claims, and cache it on the server (on cache miss, e.g. if routed to a different web server - simply use the provided access token from the cookie to request the UserInfo again). Since the access tokens can be refreshed, this would probably work fine.
- Pros: We get a properly refreshed token, that are validated by the server.
- Cons: Not all claims (e.g. aud and iss) are provided by the UserInfo endpoint, at least for Azure AD.
- Don't verify expiry of the ID token, just that it's not older than e.g. 12 hours.
- Pros: Simple, requires little effort to change from the current behavior. Has all the claims that we also have today.
- Cons: Might be a security risk? Comments?
So what is the recommended way of persisting a user's login over a longer period of time? Would using the access token with the UserInfo endpoint be a suitable solution?