.NET 10 solution for Ping, a Discord style chat app: Domain, Application and Infrastructure projects plus the Api host. SignalR for chat and presence, LiveKit for call tokens, EF Core on Postgres, S3 compatible storage for attachments, and OIDC auth shared with the Musify Zitadel instance. Includes the Compose stack for local development.
38 lines
1.2 KiB
C#
38 lines
1.2 KiB
C#
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
|
using Microsoft.Extensions.Options;
|
|
using Microsoft.IdentityModel.Tokens;
|
|
using System.Security.Claims;
|
|
|
|
namespace Ping.Api.Authentication;
|
|
|
|
public sealed class JwtBearerOptionsSetup(IOptions<AuthenticationConfiguration> options)
|
|
: IConfigureNamedOptions<JwtBearerOptions>
|
|
{
|
|
private readonly AuthenticationConfiguration _configuration = options.Value;
|
|
|
|
public void Configure(string? name, JwtBearerOptions options)
|
|
{
|
|
if (name != JwtBearerDefaults.AuthenticationScheme)
|
|
{
|
|
return;
|
|
}
|
|
|
|
Configure(options);
|
|
}
|
|
|
|
public void Configure(JwtBearerOptions options)
|
|
{
|
|
options.MetadataAddress = _configuration.MetadataAddress;
|
|
options.RequireHttpsMetadata = _configuration.RequireHttpsMetadata;
|
|
options.Audience = _configuration.AudienceAddress;
|
|
options.TokenValidationParameters = new TokenValidationParameters
|
|
{
|
|
ValidIssuer = _configuration.IssuerAddress,
|
|
ValidAudience = _configuration.AudienceAddress,
|
|
RoleClaimType = ClaimTypes.Role,
|
|
NameClaimType = ClaimTypes.Name,
|
|
};
|
|
options.EventsType = typeof(JwtBearerEventsHandler);
|
|
}
|
|
}
|