.NET API Documentation

TrewAppServerAuthenticationOptions Class

Provides options for configuring server-side application authentication. This class is used to specify details such as the authentication scheme, issuer, audience, and other relevant parameters for authenticating incoming application requests.

Syntax
public sealed class TrewAppServerAuthenticationOptions : AuthenticationSchemeOptions
Inheritance

System.Object
Microsoft.AspNetCore.Authentication.AuthenticationSchemeOptions
System.Net.Security.TrewAppServerAuthenticationOptions

Remarks

The TrewAppServerAuthenticationOptions class allows developers to finely tune how server-side authentication is performed for applications that use a custom authentication mechanism. It's designed to integrate seamlessly with ASP.NET Core's authentication middleware.

Key configuration aspects include:

Constructors

TrewAppServerAuthenticationOptions()

Initializes a new instance of the TrewAppServerAuthenticationOptions class with default settings.

public TrewAppServerAuthenticationOptions();
Properties
Name Type Description
AuthenticationScheme string Gets or sets the authentication scheme name. Defaults to "TrewAppAuthentication".
Issuer string Gets or sets the expected issuer of authentication tokens.
Audience string Gets or sets the expected audience for authentication tokens.
Authority string Gets or sets the authority that issued the authentication tokens.
TokenValidationParameters Microsoft.IdentityModel.Tokens.TokenValidationParameters Gets or sets the parameters used to validate authentication tokens.
Events Microsoft.AspNetCore.Authentication.IAuthenticationEvents Gets or sets the authentication events handler.
Examples

The following example shows how to configure TrewAppServerAuthenticationOptions in an ASP.NET Core application's Startup.cs file.

// In Startup.cs or Program.cs

services.AddAuthentication(options =>
{
    options.DefaultAuthenticateScheme = "TrewAppAuthentication";
    options.DefaultChallengeScheme = "TrewAppAuthentication";
})
.AddScheme("TrewAppAuthentication", options =>
{
    options.Issuer = "https://auth.example.com";
    options.Audience = "my-app-api";
    options.TokenValidationParameters = new Microsoft.IdentityModel.Tokens.TokenValidationParameters
    {
        ValidateIssuer = true,
        ValidateAudience = true,
        ValidateLifetime = true,
        ValidateIssuerSigningKey = true,
        ValidIssuer = "https://auth.example.com",
        ValidAudience = "my-app-api",
        IssuerSigningKey = new Microsoft.IdentityModel.Tokens.SymmetricSecurityKey(Encoding.UTF8.GetBytes("your-super-secret-key-that-should-be-long-and-secure"))
    };
    // Configure custom events if needed
    // options.Events = new TrewAppAuthenticationEvents();
});

// In a controller or Razor Page:
[Authorize(AuthenticationSchemes = "TrewAppAuthentication")]
public class MySecureController : Controller
{
    // ...
}
See Also