A simple easy to use package to manage sessions for your Client Services.
Example: Let's say you have a :code: WeatherService
, and it requires Sessions to be refreshed after every 60
seconds.
Given an authentication response like this;
{
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImowbmkiLCJuYmYiOjE2NDgwMzg2MDUsImV4cCI6MTY0ODAzODY2NSwiaWF0IjoxNjQ4MDM4NjA1fQ.T3_h3tQeXRZIbio3pTkAAdDCiKFWRxlzuQNrNd912Sw",
"expiresIn": 60,
"expiresAt": "2022-03-23T12:35:05.8707384Z"
}
you can manage sessions using Tyde like so;
- Begin by injecting the package to your instance of HttpClient like so;
services.AddHttpClient<ITydeAuthService, TydeAuthService>(config =>
{
config.BaseAddress = new Uri("https://localhost:7157");
})
.AddTyde(opts =>
{
opts.AuthenticationUrl = new Uri("https://localhost:7157/api/AuthAPI/SignIn");
opts.AuthorizingParameters = new Dictionary<string, string>()
{
{"username", "j0ni" },
{"password", "sdfdsdsd" }
};
})
Finally, add TydeDelegatingHandler
from Tyde.Core
to the HttpMessageHandler
services.AddHttpClient<IWeatherService, WeatherService>(config =>
{
config.BaseAddress = new Uri("https://localhost:7157");
})
.AddTyde(opts =>
{
opts.AuthenticationUrl = new Uri("https://localhost:7157/api/AuthAPI/SignIn");
opts.AuthorizingParameters = new Dictionary<string, string>()
{
{"username", "j0ni" },
{"password", "sdfdsdsd" }
};
}).AddHttpMessageHandler(c => c.GetService<Tyde.Core.TydeHttpDelegatingHandler>()); //mandatory
Now, all requests in the WeatherService
will be Authenticated as need.
Tyde is a simple package which uses the already robust HttpClient
library from microsoft. Ensuring the library has a small footprint, while delivering a perfect solution.
You can find docs here
Install the Tyde package
John Nyingi