I am working on a demo project where I have to implement an authorization server for the OAuth2 flow. I was investigating on the best practices for the authorization code, when I read here that:
Because authorization codes are meant to be short-lived and single-use, you could implement them as self encoded tokens. With this technique, you can avoid storing authorization codes in a database, and instead, encode all of the necessary information into the authorization code itself. You can use either a built-in encryption library of your server-side environment, or a standard such as JSON Web Signature (JWS).
It seems a very interesting approach, but I have some doubts about the single-use. Without a datastore/cache, how can the authentication server know whether it is the first time it sees the auth code (which would be an encoded token)? I mean: I could repeatedly send the same request to exchange the auth code and the authentication server would never block the requests following the first one. Do I need a particular implementation of the JWS, am I doing wrong assumptions, or single-use has another meaning in the article?