Using this approach, you will have to check the token in all your services, if you are ok with this, then you are probably fine.
The twitter access token may have an expiration time that will require the use of an update token to obtain a new access token from the auth service:
- When the access token expires, you must return 401 to the client from service X that you are trying to talk to.
- The client will have to call the Auth service providing the update token, receiving a new access token
- Finally, the client again hits Service X with this new access token, validates it, and receives the expected response from Service X.
In my recent appointment, I wrote a microservice that proxied all tokens using this approach, my proxy handled everything from auth to roles and sends 401 for expired tokens and cancels update tokens, etc. I think this gave me a greater separation of concerns.
Important Note: In the upgrade token scenario, only an invalid / expired accesstoken will be downloaded above my proxy, while in your scenario any service can be reached with invalid tokens ...
Another approach would be to allow Services A and Service-B to call an authentication service to check for tokens, but this will lead to a significant increase in traffic between services, since every HTTP request with a token needs to be checked. In this case, also an invalid token request will reach your Service X and, therefore, will put some load on it ...
source share