How do I store access token in Asp NET core 3.1?

Viewed 922

I have a ASP.NET Core 3.1 API that has to connect to another external API. To make requests to this API, it needs an OAuth 2 access token so i need to store to reuse it until it runs out and request another one if needed.

So which is the best option to store it?

I've read about using a custom class to use an static HttpClient but it doesn't work for what i have to do

3 Answers

Microsoft choose one of best way for this.

enter image description here

and you can save on your database.

if your project has a database just make a table with property token and expire time and if it doesn't save these in a text file (search about working with system.io) but it's better to use a database

You can write token to your database if your project has connection to db, or you have other options like writing to a static variable, cache or file.

Related