|
5 | 5 | using Microsoft.AspNetCore.Authentication.JwtBearer; |
6 | 6 | using Microsoft.AspNetCore.Authorization; |
7 | 7 | using Microsoft.IdentityModel.Tokens; |
| 8 | +using Scalar.AspNetCore; |
8 | 9 | using System.Text; |
9 | 10 |
|
10 | 11 |
|
|
32 | 33 | ValidAudience = appSettings.Audience, |
33 | 34 | IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(appSettings.Secret)) |
34 | 35 | }; |
35 | | - //options.Events = new JwtBearerEvents() |
36 | | - //{ |
37 | | - // OnAuthenticationFailed = c => |
38 | | - // { |
39 | | - // c.NoResult(); |
40 | | - // c.Response.StatusCode = 500; |
41 | | - // c.Response.ContentType = "text/plain"; |
42 | | - // return c.Response.WriteAsync(c.Exception.ToString()); |
43 | | - // }, |
44 | | - // OnChallenge = context => |
45 | | - // { |
46 | | - // context.HandleResponse(); |
47 | | - // context.Response.StatusCode = 401; |
48 | | - // context.Response.ContentType = "application/json"; |
49 | | - // var result = JsonSerializer.Serialize(new { Message = "You are not Authorized" }); |
50 | | - // return context.Response.WriteAsync(result); |
51 | | - // }, |
52 | | - // OnForbidden = context => |
53 | | - // { |
54 | | - // context.Response.StatusCode = 403; |
55 | | - // context.Response.ContentType = "application/json"; |
56 | | - // var result = JsonSerializer.Serialize(new { Message = "You are not authorized to access this resource" }); |
57 | | - // return context.Response.WriteAsync(result); |
58 | | - // }, |
59 | | - //}; |
60 | 36 | }); |
61 | 37 |
|
62 | 38 | builder.Services.AddSingleton<IAuthorizationPolicyProvider, CustomAuthorizationPolicyProvider>(); |
63 | 39 | builder.Services.AddScoped<IAuthorizationHandler, PermissionHandler>(); |
64 | 40 |
|
65 | 41 | builder.Services.AddControllers(); |
66 | | -// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle |
67 | | -builder.Services.AddEndpointsApiExplorer(); |
68 | | -builder.Services.AddSwaggerGen(); |
| 42 | + |
| 43 | +// Configure OpenAPI |
| 44 | +builder.Services.AddOpenApi(); |
69 | 45 |
|
70 | 46 | var app = builder.Build(); |
71 | 47 |
|
|
74 | 50 | // Configure the HTTP request pipeline. |
75 | 51 | if (app.Environment.IsDevelopment()) |
76 | 52 | { |
77 | | - app.UseSwagger(); |
78 | | - app.UseSwaggerUI(); |
| 53 | + app.MapOpenApi(); |
| 54 | + app.MapScalarApiReference(options => |
| 55 | + { |
| 56 | + options.WithTitle("Contact API") |
| 57 | + .WithTheme(ScalarTheme.BluePlanet) |
| 58 | + .WithDefaultHttpClient(ScalarTarget.CSharp, ScalarClient.HttpClient) |
| 59 | + .WithPreferredScheme("Bearer") |
| 60 | + .WithHttpBearerAuthentication(bearer => |
| 61 | + { |
| 62 | + bearer.Token = ""; |
| 63 | + }); |
| 64 | + }); |
79 | 65 | } |
| 66 | + |
80 | 67 | app.UseMiddleware<ExceptionMiddleware>(); |
81 | 68 | app.UseMiddleware<ActivityLoggingMiddleware>(); |
82 | 69 | app.UseHttpsRedirection(); |
|
0 commit comments