Something went wrong. Try again.
.NET ATProtocol Library - Built for Source Gen
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110using System;using System.Net.Http;using System.Text.Json;using CarpaNet.Identity;using CarpaNet.OAuth.Crypto;using CarpaNet.OAuth.Storage;using Microsoft.Extensions.Logging;
namespace CarpaNet.OAuth;
/// <summary>/// Configuration for the ATProto OAuth client./// </summary>public sealed class OAuthClientConfig{ /// <summary> /// The client ID. For web apps, this is the URL where client metadata is hosted. /// For loopback clients, use <see cref="CreateLoopbackClientId"/>. /// </summary> public string ClientId { get; set; } = string.Empty;
/// <summary> /// The redirect URI to use for OAuth callbacks. /// </summary> public string RedirectUri { get; set; } = string.Empty;
/// <summary> /// The scope to request (default: "atproto"). /// </summary> public string Scope { get; set; } = "atproto";
/// <summary> /// The HttpClient to use for requests. If not provided, a new one will be created. /// </summary> public HttpClient? HttpClient { get; set; }
/// <summary> /// The state store for OAuth authorization state. If not provided, an in-memory store will be used. /// </summary> public IOAuthStateStore? StateStore { get; set; }
/// <summary> /// The session store for OAuth sessions. If not provided, an in-memory store will be used. /// </summary> public IOAuthSessionStore? SessionStore { get; set; }
/// <summary> /// The private key for client authentication (if using private_key_jwt). /// </summary> public DPoPKeyPair? ClientKey { get; set; }
/// <summary> /// The state expiration time (default: 10 minutes). /// </summary> public TimeSpan StateExpiration { get; set; } = TimeSpan.FromMinutes(10);
/// <summary> /// The token refresh buffer (default: 30 seconds). /// Tokens will be refreshed this amount of time before they expire. /// </summary> public TimeSpan RefreshBuffer { get; set; } = TimeSpan.FromSeconds(30);
/// <summary> /// The JSON serializer options to use for request/response serialization. /// Should include a source-generated IJsonTypeInfoResolver for AOT compatibility. /// If not provided, a reflection-based fallback will be used. /// </summary> public JsonSerializerOptions? JsonOptions { get; set; }
/// <summary> /// Gets or sets the list of labeler DIDs whose labels should be included in responses. /// When set, the atproto-accept-labelers header is added to requests. /// </summary> public IReadOnlyList<string>? LabelerDids { get; set; }
/// <summary> /// Gets or sets the logger factory for diagnostic logging. /// When null, logging is disabled (NullLoggerFactory is used internally). /// </summary> public ILoggerFactory? LoggerFactory { get; set; }
/// <summary> /// Gets or sets the identity resolver for handle/DID resolution. /// If null, a new resolver will be created if needed. /// </summary> public IdentityResolver? IdentityResolver { get; set; }
/// <summary> /// Creates a loopback client ID for native/desktop applications. /// </summary> /// <param name="port">The local port for the callback server.</param> /// <param name="state">Optional state parameter.</param> /// <returns>A loopback client ID.</returns> public static string CreateLoopbackClientId(int port, string? state = null) { var stateParam = string.IsNullOrEmpty(state) ? "" : $"&state={Uri.EscapeDataString(state)}"; return $"http://127.0.0.1:{port}/?{stateParam}"; }
/// <summary> /// Creates a loopback redirect URI. /// </summary> /// <param name="port">The local port for the callback server.</param> /// <returns>A loopback redirect URI.</returns> public static string CreateLoopbackRedirectUri(int port) { return $"http://127.0.0.1:{port}/callback"; }}