diff --git a/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.Conversation.cs b/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.Conversation.cs index 0b17b492..2ae0d1a3 100644 --- a/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.Conversation.cs +++ b/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.Conversation.cs @@ -206,8 +206,13 @@ namespace BotSharp.Core.Repository var records = new List(); var dir = Path.Combine(_dbSettings.FileRepository, _conversationSettings.DataDir); var pager = filter?.Pager ?? new Pagination(); - var totalDirs = Directory.GetDirectories(dir); + if (!Directory.Exists(dir)) + { + Directory.CreateDirectory(dir); + } + + var totalDirs = Directory.GetDirectories(dir); foreach (var d in totalDirs) { var path = Path.Combine(d, CONVERSATION_FILE); diff --git a/src/Infrastructure/BotSharp.OpenAPI/BotSharpOpenApiExtensions.cs b/src/Infrastructure/BotSharp.OpenAPI/BotSharpOpenApiExtensions.cs index 7d6796c5..5d744f8e 100644 --- a/src/Infrastructure/BotSharp.OpenAPI/BotSharpOpenApiExtensions.cs +++ b/src/Infrastructure/BotSharp.OpenAPI/BotSharpOpenApiExtensions.cs @@ -32,7 +32,7 @@ public static class BotSharpOpenApiExtensions // Add bearer authentication var schema = "MIXED_SCHEME"; - services.AddAuthentication(options => + var builder = services.AddAuthentication(options => { // custom scheme defined in .AddPolicyScheme() below // inspired from https://weblog.west-wind.com/posts/2022/Mar/29/Combining-Bearer-Token-and-Cookie-Auth-in-ASPNET @@ -59,11 +59,6 @@ public static class BotSharpOpenApiExtensions } }).AddCookie(options => { - }).AddGitHub(options => - { - options.ClientId = config["OAuth:GitHub:ClientId"]; - options.ClientSecret = config["OAuth:GitHub:ClientSecret"]; - options.Scope.Add("user:email"); }).AddPolicyScheme(schema, "Mixed authentication", options => { // runs on each request @@ -85,6 +80,16 @@ public static class BotSharpOpenApiExtensions }; }); + if (!string.IsNullOrWhiteSpace(config["OAuth:GitHub:ClientId"]) && !string.IsNullOrWhiteSpace(config["OAuth:GitHub:ClientSecret"])) + { + builder = builder.AddGitHub(options => + { + options.ClientId = config["OAuth:GitHub:ClientId"]; + options.ClientSecret = config["OAuth:GitHub:ClientSecret"]; + options.Scope.Add("user:email"); + }); + } + // Add services to the container. services.AddControllers() .AddJsonOptions(options => @@ -106,18 +111,18 @@ public static class BotSharpOpenApiExtensions Type = SecuritySchemeType.ApiKey }); c.AddSecurityRequirement(new OpenApiSecurityRequirement { - { - new OpenApiSecurityScheme - { - Reference = new OpenApiReference { - Type = ReferenceType.SecurityScheme, - Id = "Bearer" + new OpenApiSecurityScheme + { + Reference = new OpenApiReference + { + Type = ReferenceType.SecurityScheme, + Id = "Bearer" + } + }, + Array.Empty() } - }, - Array.Empty() - } - }); + }); } );