Cant seem to fix this error:
Startup.cs
[assembly: FunctionsStartup(typeof(AiTrainer.DietTracker.Startup))]
namespace AiTrainer.DietTracker
{
public class Startup : FunctionsStartup
{
public override void Configure(IFunctionsHostBuilder builder)
{
builder.Services
.AddAuthentication(options =>
{
options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
});
// Register DarkLoop Azure Functions Authorization
builder.Services.AddFunctionsAuthorization(options =>
{
options.AddPolicy("OnlyAdmins", policy => policy.RequireRole("Admin"));
});
// Register the SwashBuckle client
// builder.Services.AddSingleton<ISwashBuckleClient, SwashBuckleClient>();
builder.Services.AddSingleton<ISwashBuckleClient, SwashBuckleClient>();
//Register the extension
builder.Services.AddSwashBuckle(opts =>
{
// If you want to add Newtonsoft support insert next line
// opts.AddNewtonsoftSupport = true;
opts.RoutePrefix = "api";
opts.SpecVersion = OpenApiSpecVersion.OpenApi3_0;
opts.AddCodeParameter = true;
opts.PrependOperationWithRoutePrefix = true;
opts.XmlPath = "TestFunction.xml";
opts.Documents = new[]
{
new SwaggerDocument
{
Name = "v1",
Title = "Swagger document",
Description = "Swagger test document",
Version = "v2"
},
new SwaggerDocument
{
Name = "v2",
Title = "Swagger document 2",
Description = "Swagger test document 2",
Version = "v2"
}
};
opts.Title = "Swagger Test";
//opts.OverridenPathToSwaggerJson = new Uri("http://localhost:7071/api/Swagger/json");
opts.ConfigureSwaggerGen = x =>
{
//custom operation example
x.CustomOperationIds(apiDesc => apiDesc.TryGetMethodInfo(out MethodInfo methodInfo)
? methodInfo.Name
: new Guid().ToString());
//custom filter example
//x.DocumentFilter<RemoveSchemasFilter>();
//oauth2
x.AddSecurityDefinition("oauth2",
new OpenApiSecurityScheme
{
Type = SecuritySchemeType.OAuth2,
Flows = new OpenApiOAuthFlows
{
Implicit = new OpenApiOAuthFlow
{
AuthorizationUrl = new Uri(";),
Scopes = new Dictionary<string, string>
{
{ "api.read", "Access read operations" },
{ "api.write", "Access write operations" }
}
}
}
});
};
});
SwaggerFunctions.cs
public class SwaggerFunctions { private readonly ISwashBuckleClient swashBuckleClient;
public SwaggerFunctions(ISwashBuckleClient swashBuckleClient)
{
this.swashBuckleClient = swashBuckleClient;
}
[SwaggerIgnore]
[Function("SwaggerJson")]
public async Task<HttpResponseData> SwaggerJson(
[Microsoft.Azure.Functions.Worker.HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "swagger/json")]
HttpRequestData req)
{
return await this.swashBuckleClient.CreateSwaggerJsonDocumentResponse(req);
}
I am using DI for azure functions, I recently upgraded to .NET 8 and I'm using the DarkLoop.Azure.Functions.Authorization.InProcess. O yeah, also here is my local.settings.json
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"FUNCTIONS_WORKER_RUNTIME": "dotnet",
"FUNCTIONS_INPROC_NET8_ENABLED": "1",
"FUNCTIONS_EXTENSION_VERSION": "~4"
}
}
Am I doing something wrong in my function app
Cant seem to fix this error:
Startup.cs
[assembly: FunctionsStartup(typeof(AiTrainer.DietTracker.Startup))]
namespace AiTrainer.DietTracker
{
public class Startup : FunctionsStartup
{
public override void Configure(IFunctionsHostBuilder builder)
{
builder.Services
.AddAuthentication(options =>
{
options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
});
// Register DarkLoop Azure Functions Authorization
builder.Services.AddFunctionsAuthorization(options =>
{
options.AddPolicy("OnlyAdmins", policy => policy.RequireRole("Admin"));
});
// Register the SwashBuckle client
// builder.Services.AddSingleton<ISwashBuckleClient, SwashBuckleClient>();
builder.Services.AddSingleton<ISwashBuckleClient, SwashBuckleClient>();
//Register the extension
builder.Services.AddSwashBuckle(opts =>
{
// If you want to add Newtonsoft support insert next line
// opts.AddNewtonsoftSupport = true;
opts.RoutePrefix = "api";
opts.SpecVersion = OpenApiSpecVersion.OpenApi3_0;
opts.AddCodeParameter = true;
opts.PrependOperationWithRoutePrefix = true;
opts.XmlPath = "TestFunction.xml";
opts.Documents = new[]
{
new SwaggerDocument
{
Name = "v1",
Title = "Swagger document",
Description = "Swagger test document",
Version = "v2"
},
new SwaggerDocument
{
Name = "v2",
Title = "Swagger document 2",
Description = "Swagger test document 2",
Version = "v2"
}
};
opts.Title = "Swagger Test";
//opts.OverridenPathToSwaggerJson = new Uri("http://localhost:7071/api/Swagger/json");
opts.ConfigureSwaggerGen = x =>
{
//custom operation example
x.CustomOperationIds(apiDesc => apiDesc.TryGetMethodInfo(out MethodInfo methodInfo)
? methodInfo.Name
: new Guid().ToString());
//custom filter example
//x.DocumentFilter<RemoveSchemasFilter>();
//oauth2
x.AddSecurityDefinition("oauth2",
new OpenApiSecurityScheme
{
Type = SecuritySchemeType.OAuth2,
Flows = new OpenApiOAuthFlows
{
Implicit = new OpenApiOAuthFlow
{
AuthorizationUrl = new Uri("https://your.idserver/connect/authorize"),
Scopes = new Dictionary<string, string>
{
{ "api.read", "Access read operations" },
{ "api.write", "Access write operations" }
}
}
}
});
};
});
SwaggerFunctions.cs
public class SwaggerFunctions { private readonly ISwashBuckleClient swashBuckleClient;
public SwaggerFunctions(ISwashBuckleClient swashBuckleClient)
{
this.swashBuckleClient = swashBuckleClient;
}
[SwaggerIgnore]
[Function("SwaggerJson")]
public async Task<HttpResponseData> SwaggerJson(
[Microsoft.Azure.Functions.Worker.HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "swagger/json")]
HttpRequestData req)
{
return await this.swashBuckleClient.CreateSwaggerJsonDocumentResponse(req);
}
I am using DI for azure functions, I recently upgraded to .NET 8 and I'm using the DarkLoop.Azure.Functions.Authorization.InProcess. O yeah, also here is my local.settings.json
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"FUNCTIONS_WORKER_RUNTIME": "dotnet",
"FUNCTIONS_INPROC_NET8_ENABLED": "1",
"FUNCTIONS_EXTENSION_VERSION": "~4"
}
}
Am I doing something wrong in my function app
Share Improve this question asked Mar 31 at 9:05 Troydon LuicienTroydon Luicien 111 silver badge5 bronze badges1 Answer
Reset to default 0ok after hours of searching and messing around with my packages I found removing this package
DarkLoop.Azure.Functions.Authorization.InProcess
and replacing with
DarkLoop.Azure.Functions.Authorization.Isolated
worked, except now I have an empty swagger UI