TwitchAuthLib 1.0.1

dotnet add package TwitchAuthLib --version 1.0.1
                    
NuGet\Install-Package TwitchAuthLib -Version 1.0.1
                    
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="TwitchAuthLib" Version="1.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="TwitchAuthLib" Version="1.0.1" />
                    
Directory.Packages.props
<PackageReference Include="TwitchAuthLib" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add TwitchAuthLib --version 1.0.1
                    
#r "nuget: TwitchAuthLib, 1.0.1"
                    
#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.
#:package TwitchAuthLib@1.0.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=TwitchAuthLib&version=1.0.1
                    
Install as a Cake Addin
#tool nuget:?package=TwitchAuthLib&version=1.0.1
                    
Install as a Cake Tool

Twitch Auth Library

Simple library to assist with getting and refreshing Twitch user and app access tokens.

Only supports the "code" and "client_credentials" grant types (and also refresh_token of course).

Usage

using TwitchAuthLib;

namespace MyApp
{
	public class MyTwitchAuth
	{
		private readonly TwitchAuth _twitchAuth;
		private GenerateSignInUrlResponse _genResponse;

		public MyTwitchAuth()
		{
			_twitchAuth = new TwitchAuth("myClientId", "myClientSecret", "http://localhost/my-signin-redirect");
		}

		public RedirectUserToTwitch()
		{
			var genResponse = _twitchAuth.GenerateSignInUrl("my space-seperated scopes here");
			_genResponse = genResponse;

			// Redirect user to url _genResponse.Url
		}

		/// <summary>
		/// This is the endpoint that the user is redirected to after they have signed in with Twitch.
		/// The function parameters are URL query parameters send back from the request to your redirect URI.
		/// </summary>
		public async Task GetAccessToken(string code, string state, string scope, string error, string error_description)
		{
			var twitchResp = new TwitchSignInRedirectResponse()
			{
				Code = code,
				State = state,
				Scope = scope,
				Error = error,
				ErrorDescription = error_description
			};

			var tokenResp = await _twitchAuth.GetTokenPair(_genResponse, twitchResp);

			// Save the tokenResp.AccessToken and tokenResp.RefreshToken somewhere
			// Also keep track of twitchResp.ExpiresIn (or twitchResp.ExpiresAt) to know when to refresh the token.
			// When it is time to renew the token, send tokenResp to the `RefreshToken` method, as seen below.

			// REMEMBER!
			// You are responsible for watching the expiry time and requesting to refresh the token when it expires.
		}

		public async Task RefreshToken(TwitchToken myToken) 
		{
			var tokenResp = await _twitchAuth.RefreshToken(myToken);

			// tokenResp will be a new instance of TwitchToken with your new token, as well
			// as the refresh token and new ExpiresIn and ExpiresAt values.
		}

		public async Task GetAppToken()
		{
			var appToken = await _twitchAuth.GetAppToken();

			// appToken is an instance o TwitchToken with the app token.
			// As with the user token, save the appToken.AccessToken, appToken.ExpiresIn, and appToken.ExpiresAt somewhere.
		}
	}
}
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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.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.0.1 170 7/25/2024
1.0.0 168 7/25/2024 1.0.0 is deprecated because it has critical bugs.