Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Azure Functions Not Appearing in Portal When Using [FunctionAuthorize] Attribute and Authentication Configuration in Startup.cs #70

Open
togosh opened this issue Oct 23, 2024 · 1 comment

Comments

@togosh
Copy link

togosh commented Oct 23, 2024

We are encountering an issue where our Azure Functions do not appear in the Azure Portal's Function App Functions list when we apply the [FunctionAuthorize] attribute from the DarkLoop.Azure.Functions.Authorize package and include authentication and authorization configuration in our Startup.cs file.

Environment Details:

Azure Functions Version:    v4
Target Framework:    .NET 8 (net8.0)
Functions Runtime:    In-Process
DarkLoop.Azure.Functions.Authorize Version:    3.1.2 and 4.0.0
Deployment Method:    Azure DevOps YAML pipeline
Hosting Environment:    Azure Function App

Problem Description:

When we include the following authentication and authorization configuration in our Startup.cs along with the [FunctionAuthorize] attribute, the functions do not appear in the Azure Portal:

// Authentication & Authorization.
JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear();

var serviceProvider = builder.Services.BuildServiceProvider();
var workflowSecrets = serviceProvider.GetService<WorkflowServerSecretsSettings>();

builder.Services
    .AddAuthentication(options =>
    {
        options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
        options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
    })
    .AddJwtBearer(options =>
    {
        options.TokenValidationParameters = new TokenValidationParameters
        {
            ValidateIssuer = false,
            ValidateAudience = false,
            ValidateLifetime = true,
            ValidIssuer = workflowSecrets.Jwt.Issuer,
            ValidAudience = workflowSecrets.Jwt.Audience,
            IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(workflowSecrets.Jwt.SecretKey)),
            NameClaimType = JwtRegistered ClaimNames.Sub
        };
    });

builder.Services.AddAuthorization(auth => auth.AddSecurityPolicy());

When we remove this code and the [FunctionAuthorize] attribute from our functions, they appear in the Azure Portal as expected.

Functionality:

  • Despite not appearing in the portal, the functions are still operational.
  • The issue seems to be that the authentication middleware is interfering with the Azure Functions host's ability to enumerate the functions or access internal endpoints.

Question:

  • Is there a recommended approach to ensure that functions appear in the Azure Portal?
@artmasa
Copy link
Contributor

artmasa commented Oct 24, 2024

At the moment there's a problem loading the right assemblies for this framework when using .NET 8 for the In-Process mode.
Issue #58 explains what is going on. Host and project should depend on same ASP.NET Core authentication packages to succeed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants