-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
68 lines (52 loc) · 1.98 KB
/
Program.cs
File metadata and controls
68 lines (52 loc) · 1.98 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
using MapController.Persistence;
using robot_controller_api.Persistence;
using FullImplementaionAPI.Persistence;
using Microsoft.OpenApi.Models;
using System.Reflection;
using FullImplementaionAPI.Authentication;
using Microsoft.AspNetCore.Authentication;
using System.Security.Claims;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllers();
// Register data access interface and implementation
builder.Services.AddScoped<IMapCommandDataAccess, MapRepository>();
builder.Services.AddScoped<IRobotCommandDataAccess, RobotCommandRepository>();
builder.Services.AddScoped<IUserDataAccess, UserRepository>();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen(options =>
{
var xmlFilename = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
options.IncludeXmlComments(Path.Combine(AppContext.BaseDirectory, xmlFilename));
options.SwaggerDoc("v1", new OpenApiInfo
{
Title = "Robot Controller API",
Description = "New backend service that provides resources for the Moon robot simulator.",
Contact = new OpenApiContact
{
Name = "Cooper Goullet",
Email = "s222326285@deakin.edu.au"
}
});
});
builder.Services.AddAuthentication("BasicAuthentication")
.AddScheme<AuthenticationSchemeOptions, BasicAuthenticationHandler>("BasicAuthentication", default);
builder.Services.AddAuthorization(options =>
{
options.AddPolicy("AdminOnly", policy =>
policy.RequireClaim(ClaimTypes.Role, "Admin"));
options.AddPolicy("UserOnly", policy =>
policy.RequireClaim(ClaimTypes.Role, "Admin", "User"));
});
var app = builder.Build();
app.UseStaticFiles();
app.UseSwagger();
app.UseSwaggerUI(setup =>
{
setup.InjectStylesheet("/styles/theme-flattop.css");
});
app.UseAuthentication();
app.UseAuthorization();
app.UseHttpsRedirection();
app.MapControllers();
app.Run();