Skip to content

Token validation

Fabrice Michellonet edited this page Mar 7, 2021 · 2 revisions

AzureFunctions.Extensions.OpenIDConect gives you full control over tokens validation.

The SetTokenValidation method let you define your own strategy by configuring a TokenValidationParameters

builder.Services.AddOpenIDConnect(config =>
            {
                config.SetTokenValidation(new TokenValidationParameters()
                {
                    ValidAudience = "api://my_audience",
                    ValidIssuer = "https://my_prefered_issuer.com",
                    ValidateAudience = true,
                    ValidateIssuer = true
                    /// ... other settings.
                });
            });

But you can also opt for a default secure settings using TokenValidationParametersHelpers.Default

builder.Services.AddOpenIDConnect(config =>
            {
                config.SetTokenValidation(TokenValidationParametersHelpers.Default(audience, issuer));
            });

which is the equivalent of

builder.Services.AddOpenIDConnect(config =>
            {
                config.SetTokenValidation(new TokenValidationParameters()
                {
                    RequireSignedTokens = true,
                    ValidateIssuerSigningKey = true,
                    ValidateLifetime = true,

                    ValidateAudience = true,
                    ValidAudience = audience,

                    ValidateIssuer = true,
                    ValidIssuer = issuer
                });
            });
Clone this wiki locally