Hello,
We are using Pomerium v0.19. Our auth provider is MS Azure. The session length is setup to 1h. We are running Pomerium in k8s and using Traefik.
We have an application opened in browser and we have issue which I can not solve or find information on how it should be handeled. When session expires, every http request fails with:
identity/oidc: user info endpoint: 401 Unauthorized: {"error":{"code":"InvalidAuthenticationToken","innerError":{"client-request-id":"d12dfb81-b326-4e77-aef9-d80730990670","date":"2023-07-23T03:59:10","request-id":"d12dfb81-b326-4e77-aef9-d80730990670"},"message":"Access token has expired or is not yet valid."}}
But I am expecting the page will be redirected to login page.
If to refresh the page, there is an error “not internet connection” which is weird. If to close and open page again, normal logging appears and everything works as expected.
What did you expect to happen?
When sessions expires, user is redirected to login.
I believe this is casual usecase which I just can’t find information about.
Would be amazing if somebody point the direction how to do this right.
As I said, “Access token has expired or is not yet valid” in 1 hour is ok. The question is, what is the best practice to handle this in application. Should application somehow check if session is still valid? What to do if session is not valid anymore, just page refresh?
Your application should receive HTTP 401 with Location header set for re-authentication. The browser normally handles that, which is why I asked for logs given that you say you do not observe the automatic redirect behaviour.
The only case where an application has to be aware and handle such a response, are XHR requests that are common in single page application, as browser would not do a page redirect then. Your application should process such response in fetch handler and cause a reload in the main document window, which would cause the main page URL be re-validated with Pomerium, that would result in a browser redirect to authenticate, a new session cookie, etc.
This make sense.
My app receives 302 instead of 401. In Pomerium I see 401. This can be explained by traefik, which “converts” 401 to 302.
Probably, the approach is the same as you described:
We are struggling with Pomerium auth performance and I think it could be related to the bug when invalid sessions were not deleted from db. But since I don’t see internal ticket, I can’t be sure this is our case.