Search code examples
jwtmicroservicestokenaws-api-gatewaygateway

How does all services in microservice architecture (token based) know that the user has logged out?


When a user logs out (sign out) of the application, how does the gateway communicate to all services that the user has logged out?

In other words, what happens when a user logs out in microservice architecture application?


Solution

  • This is generic question, I will give my personal thoughts.

    Let's take a Single page application, talking to bunch of Microservices and secured by a Gateway that validates the token.

    When user logs in, token given by auth server is stored within browser storage(ex: localstorage).

    When user log out, no communication is sent to Gateway or auth server, tokens will simply be deleted from browser storage.

    So, if someone gets hold of access tokens, they can be used to call services as long as access tokens doesn't expire.

    This is typically why there are two tokens given by auth server, an access token and a refresh token. Access token which is used to secure apis expires pretty quickly and a refresh token which has much longer expiry time can be used to get new access token.