With this in mind we can look at how token design and cryptography can lead us to a better architecture.
For all this we basically just need a Software library with a generate token and a parse token methods. There are 3 obvious benefits from this design:
Additionally, using a Token-exchange method allows for Federation.
And there’s only two requirements to be able to parse the tokens correctly:
To answer that let’s get some details about the data on a typical payload:
A token like this has roughly the following characteristics:
Now back to Logging Out. For most APIs, Revocation models is more of an edge case rather than a common task. It won’t matter much then that when using this design the Revocation model process is going to be a bit slower than usual. In brief, we’ll have to use a Back-channel Communication (e.g. a message queue) that will inform all our services that a specific token has been revoked. Each service must then store in memory (or in a fast data-store cache like Memcached or Redis) that the token has been revoked. It’s in fact much easier and faster to store only the revoked tokens rather than storing every single one. This way instead of checking if a token is valid we can just check if a payload has been de-authorized.
The process for token permission revocation and logout is therefore: (looks like OAuth 2.0 and use of the Revocation_endpoint)
OpenID Connect Back-Channel Logout and OpenID Connect Front-Channel Logout are two standard methods for Revocation model and Logging Out!! Conclusion Carefully designing our approach to tokens can have significant effects on our overall API architecture. We started by seeing how any website can become an API through simple web scraping (the happy accident). We then reviewed how a front-desk architecture works like a gateway, and its pros and cons. Then we moved to a real Service-Oriented Architecture, and how a different way of designing tokens using some encryption techniques can lead to a new design completely free of database lookups.