AuthStack.Client 1.3.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package AuthStack.Client --version 1.3.0
                    
NuGet\Install-Package AuthStack.Client -Version 1.3.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="AuthStack.Client" Version="1.3.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="AuthStack.Client" Version="1.3.0" />
                    
Directory.Packages.props
<PackageReference Include="AuthStack.Client" />
                    
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 AuthStack.Client --version 1.3.0
                    
#r "nuget: AuthStack.Client, 1.3.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.
#:package AuthStack.Client@1.3.0
                    
#: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=AuthStack.Client&version=1.3.0
                    
Install as a Cake Addin
#tool nuget:?package=AuthStack.Client&version=1.3.0
                    
Install as a Cake Tool

AuthStack.Client

AuthStack SDK for .NET - OAuth authentication client with social login support.

Installation

dotnet add package AuthStack.Client

Quick Start

using AuthStack.Client;
using AuthStack.Client.Enums;

// Create the client
var client = new AuthStackClient(new AuthStackConfig
{
    BaseUrl = "https://api.authstack.voostack.com"
});

// Initialize (restores any stored session)
await client.InitializeAsync();

// Listen for status changes
client.StatusChanged += (sender, status) =>
{
    Console.WriteLine($"Auth status changed: {status}");
};

// Login with email/password
var result = await client.LoginAsync("user@example.com", "password123");

if (result.IsSuccess)
{
    Console.WriteLine($"Logged in as {result.User!.Email}");
    Console.WriteLine($"Access token: {result.Tokens!.AccessToken}");
}
else
{
    Console.WriteLine($"Login failed: {result.Error}");
}

Features

  • Email/password authentication
  • OAuth provider login (Google, GitHub, Microsoft, Apple, Discord)
  • Provider credentials access (use GitHub/Google tokens in your app)
  • Token refresh
  • Secure token storage (customizable)
  • Async/await support
  • Event-based status updates
  • JWKS support for token validation

OAuth Provider Login

// Using an ID token (e.g., from Google Sign-In)
var result = await client.LoginWithProviderTokenAsync(
    OAuthProvider.Google,
    googleIdToken
);

// Using an authorization code (redirect flow)
var result = await client.LoginWithProviderCodeAsync(
    OAuthProvider.GitHub,
    authorizationCode,
    "https://myapp.com/callback"
);

When using GitHub OAuth, request these scopes for full functionality:

Scope Purpose
repo Access private repositories
read:user Read user profile data
user:email Access user email addresses

Example OAuth URL:

https://github.com/login/oauth/authorize?client_id=YOUR_CLIENT_ID&scope=repo,read:user,user:email&redirect_uri=YOUR_REDIRECT_URI

Centralized OAuth Flow

AuthStack handles OAuth app configuration centrally, so you don't need your own OAuth credentials. Use GetProviderAuthUrlAsync() to start an OAuth flow:

// Get the OAuth authorization URL for GitHub
var authUrl = await client.GetProviderAuthUrlAsync(
    OAuthProvider.GitHub,
    "https://yourapp.com/oauth/callback"
);

// Redirect user to authUrl.AuthorizationUrl
// After authorization, use the code to link the provider
var linked = await client.LinkProviderWithCodeAsync(
    OAuthProvider.GitHub,
    codeFromCallback,
    "https://yourapp.com/oauth/callback"
);

This works with all supported providers:

  • GitHub
  • Google
  • Microsoft
  • Apple
  • Discord

Provider Credentials

After linking an OAuth provider, you can retrieve the provider's access token to make API calls on behalf of the user:

// Get GitHub credentials to interact with GitHub API
var credentials = await client.GetProviderCredentialsAsync(OAuthProvider.GitHub);

// Use with Octokit (GitHub .NET SDK)
var github = new GitHubClient(new ProductHeaderValue("MyApp"));
github.Credentials = new Credentials(credentials.AccessToken);
var repos = await github.Repository.GetAllForCurrent();

// Or with HttpClient
var httpClient = new HttpClient();
httpClient.DefaultRequestHeaders.Authorization =
    new AuthenticationHeaderValue("Bearer", credentials.AccessToken);
var response = await httpClient.GetAsync("https://api.github.com/user/repos");

The ProviderCredentials object contains:

  • AccessToken - OAuth access token for the provider
  • RefreshToken - Refresh token (if available)
  • ExpiresAt - Token expiration time (if known)
  • Scopes - Granted OAuth scopes
  • IsExpired - Whether the token has expired

Token Management

// Check authentication status
if (client.IsAuthenticated)
{
    // Get current user
    var user = client.CurrentUser;
    Console.WriteLine($"Hello, {user!.FullName}");

    // Get access token for API calls
    var accessToken = client.AccessToken;
}

// Refresh token
var success = await client.RefreshTokenAsync();

// Logout
await client.LogoutAsync();

Custom Token Storage

By default, tokens are stored in memory. For production, implement ITokenStorage:

public class SecureTokenStorage : ITokenStorage
{
    public Task SaveTokensAsync(AuthTokens tokens, CancellationToken ct = default)
    {
        // Save to secure storage
    }

    public Task<AuthTokens?> GetTokensAsync(CancellationToken ct = default)
    {
        // Retrieve from secure storage
    }

    public Task ClearTokensAsync(CancellationToken ct = default)
    {
        // Clear from secure storage
    }

    public Task<bool> HasTokensAsync(CancellationToken ct = default)
    {
        // Check if tokens exist
    }
}

// Use custom storage
var client = new AuthStackClient(new AuthStackConfig
{
    BaseUrl = "https://api.authstack.voostack.com",
    TokenStorage = new SecureTokenStorage()
});

JWKS Token Validation

AuthStack supports JWKS (JSON Web Key Set) for validating tokens without shared secrets. This is useful for backend services that need to verify AuthStack tokens.

.NET Backend Validation

services.AddAuthentication()
    .AddJwtBearer(options =>
    {
        options.Authority = "https://api.authstack.voostack.com";
        options.TokenValidationParameters = new TokenValidationParameters
        {
            ValidateIssuer = true,
            ValidIssuer = "https://api.authstack.voostack.com",
            ValidateAudience = true,
            ValidAudience = "authstack"
        };
    });

Endpoints

Endpoint Description
/.well-known/jwks.json JSON Web Key Set for token validation
/.well-known/openid-configuration OpenID Connect discovery document

API Reference

AuthStackClient

Property Type Description
Status AuthStatus Current authentication status
CurrentUser UserInfo? Current authenticated user
Tokens AuthTokens? Current auth tokens
IsAuthenticated bool Whether user is authenticated
AccessToken string? Current access token
Method Description
InitializeAsync() Initialize and restore session
LoginAsync() Login with email/password
RegisterAsync() Register new user
LoginWithProviderTokenAsync() Login with OAuth token
LoginWithProviderCodeAsync() Login with OAuth code
RefreshTokenAsync() Refresh access token
FetchCurrentUserAsync() Refresh user data
GetLinkedProvidersAsync() Get linked OAuth providers
LinkProviderWithTokenAsync() Link OAuth provider with token
LinkProviderWithCodeAsync() Link OAuth provider with code
UnlinkProviderAsync() Unlink OAuth provider
GetProviderAuthUrlAsync() Get OAuth authorization URL for provider
GetProviderCredentialsAsync() Get provider access token
LogoutAsync() Logout and clear tokens

Events

Event Description
StatusChanged Fired when auth status changes
UserChanged Fired when current user changes

License

MIT

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.3.1 145 1/17/2026
1.3.0 87 1/16/2026
1.2.0 93 1/16/2026
1.1.0 98 1/15/2026