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.
public sealed class TrewAppServerAuthenticationOptions : AuthenticationSchemeOptions
System.Object
Microsoft.AspNetCore.Authentication.AuthenticationSchemeOptions
System.Net.Security.TrewAppServerAuthenticationOptions
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:
- Authentication Scheme: The name of the authentication scheme this configuration belongs to.
- Issuer: The entity that issues security tokens or credentials.
- Audience: The intended recipient of the security tokens or credentials.
- Token Validation Parameters: Advanced settings for validating tokens, such as signature validation, time skew, and lifetime checks.
- Events: Custom handlers for authentication events like on authentication success or failure.
TrewAppServerAuthenticationOptions()
Initializes a new instance of the TrewAppServerAuthenticationOptions
class with default settings.
public TrewAppServerAuthenticationOptions();
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. |
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
{
// ...
}