OAuth authorized HttpClient, friendly with HttpClientFactory
- GSS.Authorization.OAuth
- GSS.Authorization.OAuth.HttpClient
- GSS.Authorization.OAuth2
- GSS.Authorization.OAuth2.HttpClient
# OAuth 1.0 protocol
dotnet add package GSS.Authorization.OAuth.HttpClient
# OAuth 2.0 protocol
dotnet add package GSS.Authorization.OAuth2.HttpClient
- Only provide
HMAC-SHA1
andPLAINTEXT
signature method. You can implementGSS.Authorization.OAuth.IRequestSigner
to support more signature methods. - Only provide
InteractiveConsoleAuthorizer
grant flow. You can implementGSS.Authorization.OAuth.IAuthorizer
to support more grant flows.
- Only provide
Client-Credentials
andResource-Owner-Credentials
grant flow, You can implementGSS.Authorization.OAuth2.IAuthorizer
to support more grant flows.
Check out these samples to learn the basics and key features.
services.AddOAuthHttpClient("oauth",(resolver, options) =>
{
var configuration = resolver.GetRequiredService<IConfiguration>();
options.ClientCredentials = new OAuthCredential(configuration["OAuth:ClientId"], configuration["OAuth:ClientSecret"]);
options.TokenCredentials = new OAuthCredential(configuration["OAuth:TokenId"],configuration["OAuth:TokenSecret"]);
options.SignedAsQuery = configuration.GetValue("OAuth:SignedAsQuery", false);
});
services.AddOAuthHttpClient<OAuthHttpClient>((resolver, options) =>
{
var configuration = resolver.GetRequiredService<IConfiguration>();
options.ClientCredentials = new OAuthCredential(configuration["OAuth:ClientId"], configuration["OAuth:ClientSecret"]);
options.TokenCredentials = new OAuthCredential(configuration["OAuth:TokenId"],configuration["OAuth:TokenSecret"]);
options.SignedAsQuery = configuration.GetValue("OAuth:SignedAsQuery", false);
});
services.AddOAuth2HttpClient<ClientCredentialsAuthorizer>("oauth2",(resolver, options) =>
{
var configuration = resolver.GetRequiredService<IConfiguration>();
options.AccessTokenEndpoint = configuration.GetValue<Uri>("OAuth2:AccessTokenEndpoint");
options.ClientId = configuration["OAuth2:ClientId"];
options.ClientSecret = configuration["OAuth2:ClientSecret"];
options.Credentials = new NetworkCredential(configuration["OAuth2:Credentials:UserName"], configuration["OAuth2:Credentials:Password"]);
options.Scopes = configuration.GetSection("OAuth2:Scopes").Get<IEnumerable<string>>();
});
services.AddOAuth2HttpClient<OAuth2HttpClient, ResourceOwnerCredentialsAuthorizer>((resolver, options) =>
{
var configuration = resolver.GetRequiredService<IConfiguration>();
options.AccessTokenEndpoint = configuration.GetValue<Uri>("OAuth2:AccessTokenEndpoint");
options.ClientId = configuration["OAuth2:ClientId"];
options.ClientSecret = configuration["OAuth2:ClientSecret"];
options.Credentials = new NetworkCredential(configuration["OAuth2:Credentials:UserName"], configuration["OAuth2:Credentials:Password"]);
options.Scopes = configuration.GetSection("OAuth2:Scopes").Get<IEnumerable<string>>();
});