Patreon.Api 1.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Patreon.Api --version 1.0.0                
NuGet\Install-Package Patreon.Api -Version 1.0.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Patreon.Api" Version="1.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Patreon.Api --version 1.0.0                
#r "nuget: Patreon.Api, 1.0.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Patreon.Api as a Cake Addin
#addin nuget:?package=Patreon.Api&version=1.0.0

// Install Patreon.Api as a Cake Tool
#tool nuget:?package=Patreon.Api&version=1.0.0                

Patreon Api

NuGet Version Build GitHub License

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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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