@vinamelody so you need to save the token somewhere. If this is a web app you could save it in the user’s session, otherwise you’d need to save it in the database along with the user in a user table.
If this token is not user specific then you can save it in a shared container. Have a look at how the auth cache works for sharing data across requests. Hope that helps!
@0xtim this vapor app is a kind of middleman between ticketing system (tito webhook) and auth0, there won’t be user’s session, therefore, machine to machine app. I guess database would be the way. But that would mean, I am storing auth0’s access token in database ~~ is that okay for production?
To use auth cache, does that require Vapor itself handling auth and JWT?
I’m thinking of something simpler like setting a timer for Vapor app to get a new access token after 24 hours. Is there something like that?
Yes you could store it in a database, but I’d probably just store it in memory, it will be easier. What I would do is define a service that makes a request to Auth0 to get the token and just stores it in memory (you either need to make it thread safe or have a service for each thread). Then if you get a 401 just use the service to call the endpoint and get an updated token. So the first time you ask the service for the token it will see if it has it and if not go and get it. The next time it just returns the token until the token no longer works. Does that make sense?