-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
57 lines (52 loc) · 1.87 KB
/
Copy pathProgram.cs
File metadata and controls
57 lines (52 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
using HoTeach.Infrastructure.Configuration;
using HoTeach.Infrastructure.Extensions;
using HoTeach.Payments.Services;
using Microsoft.Azure.Functions.Worker.Builder;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.IdentityModel.Tokens;
using MongoDB.Bson;
using MongoDB.Driver;
using OpenAI.Chat;
var builder = FunctionsApplication.CreateBuilder(args);
builder.ConfigureFunctionsWebApplication();
builder.Services
.AddAuthentication(options =>
{
options.DefaultAuthenticateScheme = "Bearer";
options.DefaultChallengeScheme = "Bearer";
})
.AddJwtBearer("Bearer", options =>
{
options.Authority = "https://dev-m31s5020w8rygw8y.us.auth0.com";
options.Audience = "https://hoteachaudience.com";
options.TokenValidationParameters = new TokenValidationParameters
{
ValidateIssuer = true,
ValidIssuer = $"https://dev-m31s5020w8rygw8y.us.auth0.com",
ValidateAudience = true,
ValidAudience = "https://hoteachaudience.com",
ValidateLifetime = true,
};
});
builder.Services.AddSingleton(new ChatClient(model: "gpt-4o-mini", Environment.GetEnvironmentVariable("OpenAIApiKey")));
var mongoConfig = builder.Configuration.GetSection("Mongo");
string mongoUrl = mongoConfig["Url"];
string databaseName = mongoConfig["Database"];
builder.Services.AddMongoDatabase(p =>
{
p.WithConnectionString(mongoUrl);
p.WithDatabaseName(databaseName);
p.WithSoftDeletes(o =>
{
o.Enabled(true);
});
p.RepresentEnumValuesAs(BsonType.String);
p.WithIgnoreIfDefaultConvention(false);
p.WithIgnoreIfNullConvention(true);
});
//builder.Services
// .AddApplicationInsightsTelemetryWorkerService()
// .ConfigureFunctionsApplicationInsights();
builder.Build().Run();