You can save JWT in db, but you will lose some of the benefits of JWT. JWT gives you the advantage of not having to check the token in db every time, as you can just use cryptography to make sure the token is legal. If you need to find a token in db, you can simply use an opaque token that does not carry information with you, and let the server and database provide you with information. On the other hand, if you are going to store a token in db, I don't think JWT is a bad choice for your type of token. As you say, there are benefits to revocation if you store your token in db. It all depends on what you want to achieve (faster authorization, etc. And the ability to cancel on demand).
You can still use JWT with OAuth2 without storing tokens in db if you want. JWTs have a custom expiration time that you can set, after which they are invalid. Access tokens (whether JWT or not) should usually be short-lived for security. If the problem is that someone stole the phone and gained access to the tokens, I think the solution is to get those tokens to expire quickly (30 minutes?). If you use oauth2, the way to stop someone from continuing to use the application is to allow the real owner to cancel authorization of the mobile application client on the authorization server so that no more access tokens are issued.
sdoxsee
source share