-
Notifications
You must be signed in to change notification settings - Fork 46
Expand file tree
/
Copy pathProgram.cs
More file actions
71 lines (56 loc) · 2.54 KB
/
Program.cs
File metadata and controls
71 lines (56 loc) · 2.54 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// Copyright (c) Duende Software. All rights reserved.
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Serilog;
using System;
using Duende.AccessTokenManagement;
using Duende.IdentityModel.Client;
using Microsoft.Extensions.Options;
using Serilog.Sinks.SystemConsole.Themes;
namespace WorkerService;
public class Program
{
public static void Main(string[] args)
{
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Debug()
.WriteTo.Console(theme: AnsiConsoleTheme.Code)
.CreateLogger();
CreateHostBuilder(args).Build().Run();
}
public static IHostBuilder CreateHostBuilder(string[] args)
{
var host = Host.CreateDefaultBuilder(args)
.UseSerilog()
.ConfigureServices((services) =>
{
services.AddClientCredentialsTokenManagement();
services.AddSingleton(new DiscoveryCache("https://demo.duendesoftware.com"));
services.AddSingleton<IConfigureOptions<ClientCredentialsClient>, ClientCredentialsClientConfigureOptions>();
// alternative way to add a client
services.Configure<ClientCredentialsClient>("demo", client =>
{
client.TokenEndpoint = "https://demo.duendesoftware.com/connect/token";
client.ClientId = "m2m.short";
client.ClientSecret = "secret";
client.Scope = "api";
});
services.AddClientCredentialsHttpClient("client", "demo", client =>
{
client.BaseAddress = new Uri("https://demo.duendesoftware.com/api/");
});
services.AddHttpClient<TypedClient>(client =>
{
client.BaseAddress = new Uri("https://demo.duendesoftware.com/api/");
})
.AddClientCredentialsTokenHandler("demo");
services.AddTransient<IClientAssertionService, ClientAssertionService>();
//services.AddHostedService<WorkerManual>();
services.AddHostedService<WorkerManualJwt>();
//services.AddHostedService<WorkerHttpClient>();
//services.AddHostedService<WorkerTypedHttpClient>();
});
return host;
}
}