I'm currently working on a pure server-side solution to consume an existing rest API, authenticated with a JWT token, in ASP.NET Core 2.
I have a Core 2 MVC project set up and included refit to to consume the api.
What I ideally want to do is to 1. Use the Refit HttpClientFactory libraries to sent a request to fetch the jwt token on the api and 2. include the token in all subsequent api calls.
I was looking into this and it is quite similar as to what Im looking to do but it needs to be a core 2 based solution.
I've already got a working solution using refit to get the jwt token from /api/login and storing it in a session variable, but this doesnt feel like the right way of doing it.
var client = new RestClient("localhost:5000/api/login");
var request = new RestRequest(Method.POST);
request.AddJsonBody("User Model that I created");
request.AddHeader("Accept", "application/json");
request.RequestFormat = DataFormat.Json;
IRestResponse response = client.Execute(request);
//Store the response token in session
//Subsequent calls
var client = new RestClient("localhost:5000/api/values");
var request = new RestRequest(Method.GET);
request.AddHeader("authorization", "Bearer TOKEN_FROM_SESSION_STORAGE");
request.AddHeader("content-type", "application/json");
IRestResponse response = client.Execute(request);
Have someone maybe worked on something like this before, just to nudge me in the right direction ?