Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

droosma/OAuth.HttpClient

Open more actions menu

Repository files navigation

OAuth.HttpClient

A DelegatingHandler implementation that abstracts away some of the authentication handshake logic like requesting the jwt token caching, and refreshing it.

NuGet version (ResilientOAuth.HttpClient)

Usage

    public void ConfigureServices(IServiceCollection services)
    {
        var settings = new Settings(clientId: "id",
                                    clientSecret: "secret",
                                    scope: "role:app",
                                    endpoint: new Uri("https://authority.local"),
                                    expireMargin: TimeSpan.FromMinutes(10));
        services.AddHttpClient("authenticatedHttpClient").WithOAuth(settings);
    }

Configuration

To facilitate configuration from IConfiguration you can use the SettingsDto to create the required settings directly from IConfiguration

Add the required settings to your appsettings.json

{
  "OAuthSettings": {
    "ClientId": "client_id",
    "ClientSecret": "client_secret",
    "Scopes": ["api1", "api2"],
    "TokenEndpoint": "https://localhost:5001/connect/token"
  }
}

Initialize the client with the correct settings (or any other ConfigurationSource)

var settings = hostBuilder.Configuration.GetRequiredSection("OAuthSettings").Get<SettingsDto>();
hostBuilder.Services.AddHttpClient("authenticatedHttpClient").WithOAuth(settings);

About

A HttpClient DelegatingHandler that handles OAuth handschake

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages

Morty Proxy This is a proxified and sanitized view of the page, visit original site.