/oauth2-client-handler

Managed .NET (C#) library for use with HttpClient to transparantly call authorized WebAPI

Primary LanguageC#MIT LicenseMIT

OAuth2 Client Handler

Build status

Managed .NET library for use with HttpClient to transparantly call authorized remote API protected with OAuth2 or OpenID Connect.

Supports .NET Framework 4.5+ and .NET Standard / .NET Core.

Get it on NuGet

PM> Install-Package OAuth2ClientHandler

Usage

var options = new OAuthHttpHandlerOptions
{
    AuthorizerOptions = new AuthorizerOptions
    {
        AuthorizeEndpointUrl = new Uri("http://localhost/authorizer"),
        TokenEndpointUrl = new Uri("http://localhost/token"),
        ClientId = "MyId",
        ClientSecret = "MySecret",
        GrantType = GrantType.ClientCredentials
    }
};

using (var client = new HttpClient(new OAuthHttpHandler(options)))
{
    client.BaseAddress = new Uri("http://localhost");
    var response = await client.GetAsync("/api/protected_api_call");
    // ...
}