Patreon.Api
1.2.0
See the version list below for details.
dotnet add package Patreon.Api --version 1.2.0
NuGet\Install-Package Patreon.Api -Version 1.2.0
<PackageReference Include="Patreon.Api" Version="1.2.0" />
paket add Patreon.Api --version 1.2.0
#r "nuget: Patreon.Api, 1.2.0"
// Install Patreon.Api as a Cake Addin #addin nuget:?package=Patreon.Api&version=1.2.0 // Install Patreon.Api as a Cake Tool #tool nuget:?package=Patreon.Api&version=1.2.0
Patreon Api
A minimal .NET Client for Patreon API v2 using Refit and Polly. Supports automatic refresh of expired access tokens.
Usage
Setup with Dependency Injection
using Patreon.Api.Extensions;
var services = new ServiceCollection();
services.AddPatreonApi(options =>
{
options.ClientId = "your-client-id";
options.ClientSecret = "your-client-secret";
});
Inject the IPatreonApi Polly Client to use
using Patreon.Api;
public class MyService(IPatreonApi patreonApi)
{
// Get the active tier ids for a user based on your campaign id
public async Task GetTiers()
{
AuthorizationTokens tokens = new()
{
AccessToken = "your-user-access-token",
RefreshToken = "your-user-refresh-token"
};
PatreonIdentityResponse response = await patreonApi.GetIdentity(
include: "memberships.campaign,memberships.currently_entitled_tiers"
authorization: tokens
);
// If automatic token refresh occured, the `tokens` object will have updated properties with the new tokens
// - tokens.AccessToken
// - tokens.AccessTokenExpiration
// - tokens.RefreshToken
IReadOnlyList<string>? tiers = response.GetTierIds("your-campaign-id");
}
// Manually refreshing the access + refresh tokens using a user refresh token and your client id + secret
public async Task ManualTokenRefresh()
{
PatreonTokenResponse response = await patreonApi.GetToken(
PatreonTokenRequest.FromRefreshToken(
authTokens.RefreshToken,
"your-client-id",
"your-client-secret"
)
);
}
// Getting access + refresh tokens using a code from the Patreon OAuth2 flow
public async Task GetTokensFromCode(string code)
{
PatreonTokenResponse response = await patreonApi.GetToken(
PatreonTokenRequest.FromCode(
code,
"your-client-id",
"your-client-secret",
"your-redirect-uri"
)
);
}
}
Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
License
This project is licensed under the Apache 2.0 License - see the LICENSE file for details.
Disclaimers
All trademarks, logos, and brand names are the property of their respective owners. All company, product and service names used in this document and licensed applications are for identification purposes only. Use of these names, trademarks, and brands does not imply endorsement.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net8.0
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.1)
- Microsoft.Extensions.Http.Polly (>= 8.0.8)
- Refit (>= 7.2.1)
- Refit.HttpClientFactory (>= 7.2.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.2.1 | 110 | 11/3/2024 |
1.2.0 | 155 | 10/12/2024 |
1.1.1 | 120 | 10/10/2024 |
1.1.0 | 111 | 10/10/2024 |
1.0.0 | 110 | 10/8/2024 |
1.0.0-pre.2 | 48 | 10/8/2024 |
1.0.0-pre.1 | 47 | 10/8/2024 |