ASP.Net 9.0: Authentication Enhancements
Tags: dotnet, aspnet, csharp, security
Published: 2024-03-16 14:53:26

The article demonstrates new features related to authentication and authorization. These enhancements aim to improve security and streamline the process of verifying user identities and granting access.

## OIDC and OAuth Parameter Customization

The OAuth and OpenID Connect (OIDC) authentication handlers now offer an AdditionalAuthorizationParameters option. This feature simplifies the customization of authorization message parameters typically included in the redirect query string. Previously, achieving this level of customization required implementing a custom OnRedirectToIdentityProvider callback or overriding the BuildChallengeUrl method within a custom handler. However, with the latest improvements, developers can achieve the same result more succinctly.

## Example

In previous versions of .NET, achieving custom parameter customization looked like this:
```
    builder.Services.AddAuthentication().AddOpenIdConnect(options =>
    {
        options.Events.OnRedirectToIdentityProvider = context =>
        {
            context.ProtocolMessage.SetParameter("prompt", "login");
            context.ProtocolMessage.SetParameter("audience", "https://api.example.com");
            return Task.CompletedTask;
        };
    });

```
Now, with the simplified approach, you can achieve the same result as follows

```
    builder.Services.AddAuthentication().AddOpenIdConnect(options =>
    {
        options.AdditionalAuthorizationParameters.Add("prompt", "login");
        options.AdditionalAuthorizationParameters.Add("audience", "https://api.example.com");
    });
```
## Configuring HTTP.sys Extended Authentication Flags

Windows authentication via HTTP.sys can now be fine-tuned using the EnableKerberosCredentialCaching and CaptureCredentials properties. These properties allow developers to optimize how HTTP.sys handles authentication. Specifically, you can configure the following flags:

 1. **HTTP_AUTH_EX_FLAG_ENABLE_KERBEROS_CREDENTIAL_CACHING**: Enables Kerberos credential caching for improved performance.

 2. **HTTP_AUTH_EX_FLAG_CAPTURE_CREDENTIAL**: Captures user credentials during the authentication process.

## Example:
```
    webBuilder.UseHttpSys(options =>
    {
        options.Authentication.Schemes = AuthenticationSchemes.Negotiate;
        options.Authentication.EnableKerberosCredentialCaching = true;
        options.Authentication.CaptureCredentials = true;
    });
```
### C# Programming🚀

Thank you for being a part of the C# community! Before you leave:

#### If you’ve made it this far, please show your appreciation with a clap and follow the author! 👏️️

Follow us: [X](https://twitter.com/sukhsukhpinder) | [LinkedIn](https://www.linkedin.com/in/sukhpinder-singh/) | [Dev.to](https://dev.to/ssukhpinder) | [Hashnode](https://dotnet.hashnode.dev/) | [Newsletter](https://www.linkedin.com/newsletters/net-programming-7031098498754195456/) | [Tumblr](https://www.tumblr.com/settings/blog/codewithsukh)

Visit our other platforms: [GitHub](https://github.com/ssukhpinder) | [Instagram](https://www.instagram.com/codewithsukh/) | [Tiktok](https://www.tiktok.com/@codewithsukh) | [Quora](https://www.quora.com/profile/Sukhpinder-Singh-4) | [Daily.dev](https://app.daily.dev/devcard)

More content at [C# Programming](https://medium.com/c-sharp-progarmming)