OAUTH2 Resource Server Token Validation#
How Does Resource Server Validate Token?#
- In the OAUTH2 Flow, we have discussed about main flows for applying OAUTH2 and we can know that everytime the
Clientwant to access theResource Server, it must provide the token which is received from theAuth Serverto theResource Server. So then theResource Servercan validate and response data to theClient. - Usually, we will have three main ways to apply for
Resource Serverto validate access token.
Direct Api Call#
- As you can see in the image above, every time the
Resource Serverreceives the access token from theClient, It has to validate that token with theAuth Serverby calling theAuth Serverapi for token validation. Because these are two different servers or two different applications handling different responsibilities. Thus, theResource Serveris not aware of the access tokens issued by theAuth Serverto all the clients. So theResource Serverhave to send the access token toAuth Serverfor validation.
Common Database#
- From the image above, we can see the
Auth Serverand theResource Serveris connecting to the same database. So whenever theAuth Serverissues an access token, it can write into the database and theResource Servercan connect to this database to get the access token and validate it with the one received from theClient. - In this scenarios, the
Resource Serverdoesn't have to rely on the network interact with theAuth Server.
Token Signature#
- In the Token Authentication With JWT, we know that the signature of the tokens can be validated by having some secret keys maintained by the both parties to make sure that no one is tampered.
- Following the same approach, the
Auth Servercan generate an access token by using some encryption algorithm with the secret. Then, whenever theClientsends the same access token to theResource Server, so theResource Serverdoesn't have to make a call toAuth Serveror doesn't have to look into the database. It can simply check the signature or hash value of the token generated with the encryption algorithm that it maintains to understand the token is valid or not.
Summary#
- Every approach has it's own pros and cons. In the
Token Signatureapproach which is used for validating the token signature, so you will never depend on the network to callAuth Serveror database. But if we have a clear and real time checking withAuth Server, you can always rely on theDirect Api Callapproach. But if you don't want to overburden theAuth Servernetwork so you can maintain aCommon Databasewhich can be leveraged by bothAuth ServerandResource Server.


