You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					
					
						
							110 lines
						
					
					
						
							3.3 KiB
						
					
					
				
			
		
		
		
			
			
			
				
					
				
				
					
				
			
		
		
	
	
							110 lines
						
					
					
						
							3.3 KiB
						
					
					
				| using Microsoft.AspNetCore.Authentication.JwtBearer; | |
| using Microsoft.AspNetCore.ResponseCompression; | |
| using Microsoft.EntityFrameworkCore; | |
| using Microsoft.IdentityModel.Tokens; | |
| using Microsoft.OpenApi.Models; | |
| using System.Text.Json.Serialization; | |
| using System.Text; | |
| using Biskilog_Accounting.Server; | |
| 
 | |
| var builder = WebApplication.CreateBuilder(args); | |
| 
 | |
| // Add services to the container. | |
| builder.Services.AddControllers().AddJsonOptions(x => x.JsonSerializerOptions.ReferenceHandler = ReferenceHandler.IgnoreCycles); | |
| builder.Services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies()); | |
| builder.Logging.ClearProviders(); | |
| builder.Logging.AddConsole(); | |
| builder.Services.AddEntityFrameworkMySql().AddDbContext<BiskilogClientsContext>(options => | |
| { | |
|     options.UseMySql(builder.Configuration.GetConnectionString("Connection"), new MariaDbServerVersion(new Version())); | |
| }); | |
| //builder.Services.AddScoped<IAuthService, AuthRepo>(); | |
|  | |
| builder.Services.AddCors(options => | |
| { | |
|     options.AddPolicy("CorsPolicy", | |
|         builder => builder.AllowAnyOrigin() | |
|         .AllowAnyMethod() | |
|         .AllowAnyHeader() | |
|         ); | |
| }); | |
| builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme).AddJwtBearer(options => | |
| { | |
|     options.RequireHttpsMetadata = false; | |
|     options.SaveToken = true; | |
|     options.TokenValidationParameters = new TokenValidationParameters() | |
|     { | |
|         ValidateIssuer = true, | |
|         ValidateAudience = true, | |
|         ValidAudience = builder.Configuration["Jwt:Audience"], | |
|         ValidIssuer = builder.Configuration["Jwt:Issuer"], | |
|         IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(builder.Configuration["Jwt:Key"])) | |
|     }; | |
| }); | |
| builder.Services.AddEndpointsApiExplorer(); | |
| builder.Services.AddSwaggerGen(c => | |
| { | |
|     c.SwaggerDoc("v1", new OpenApiInfo { Title = "MyBlazor", Version = "v1" }); | |
|     c.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme | |
|     { | |
|         In = ParameterLocation.Header, | |
|         Description = "Please enter a valid token", | |
|         Name = "Authorization", | |
|         Type = SecuritySchemeType.Http, | |
|         BearerFormat = "JWT", | |
|         Scheme = "Bearer" | |
|     }); | |
|     c.AddSecurityRequirement(new OpenApiSecurityRequirement | |
|     { | |
|         { | |
|             new OpenApiSecurityScheme | |
|             { | |
|                 Reference = new OpenApiReference | |
|                 { | |
|                     Type=ReferenceType.SecurityScheme, | |
|                     Id="Bearer" | |
|                 } | |
|             }, | |
|             new string[]{} | |
|         } | |
|     }); | |
| }); | |
| builder.Services.AddControllersWithViews(); | |
| builder.Services.AddRazorPages(); | |
| 
 | |
| var app = builder.Build(); | |
| 
 | |
| // Configure the HTTP request pipeline. | |
| if (app.Environment.IsDevelopment()) | |
| { | |
| 
 | |
|     app.UseWebAssemblyDebugging(); | |
|     app.UseSwagger(); | |
|     app.UseSwaggerUI(c => | |
|     { | |
|         c.SwaggerEndpoint("/swagger/v1/swagger.json", "MyBlazor v1"); | |
|         c.RoutePrefix = "api/docs"; | |
|     }); | |
| } | |
| else | |
| { | |
|     app.UseExceptionHandler("/Error"); | |
|     // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. | |
|     app.UseHsts(); | |
| } | |
| app.UseHttpsRedirection(); | |
| 
 | |
| app.UseBlazorFrameworkFiles(); | |
| app.UseStaticFiles(); | |
| 
 | |
| app.UseRouting(); | |
| app.UseCors("CorsPolicy"); | |
| 
 | |
| app.UseAuthentication(); | |
| app.UseAuthorization(); | |
| 
 | |
| app.MapRazorPages(); | |
| app.MapControllers(); | |
| app.MapFallbackToFile("index.html"); | |
| 
 | |
| app.Run();
 | |
| 
 |