The middleware only validates the token.
The oauth authorization server assigns the token. The configuration of this server controls the expiration. For example, with azure ad, you can configure up to 2 hours. Refresh tokens can have longer lifetimes.
The client calling the middleware stores the token. The client library is configured for storage.
Note: if the middleware makes a new request with a bearer token, it uses the passed bearer token plus its own credentials to call the oauth server to get a new access token.