Skip to content
/ tyde Public

A simple way to manage sessions for JWT client services

License

Notifications You must be signed in to change notification settings

j0nimost/tyde

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

81 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Tyde

logo

Documentation Status

A simple easy to use package to manage sessions for your Client Services.

Summary

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.

Docs

You can find docs here

How To

Install the Tyde package

Author

John Nyingi

About

A simple way to manage sessions for JWT client services

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages