-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAppSetup.cs
More file actions
64 lines (61 loc) · 2.5 KB
/
Copy pathAppSetup.cs
File metadata and controls
64 lines (61 loc) · 2.5 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
using API;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.Extensions.Options;
using Microsoft.OpenApi.Models;
using Common;
public static class AppSetup
{
public static void AddMySwaggerGen(this IServiceCollection services, IConfiguration configuration)
{
var clientId = configuration["AzureAd:ClientId"];
var tenantId = configuration["AzureAd:TenantId"];
services.AddSwaggerGen(setupAction =>
{
//setupAction.AddSecurityDefinition("oauth2", new OpenApiSecurityScheme
//{
// Type = SecuritySchemeType.OAuth2,
// Flows = new OpenApiOAuthFlows
// {
// AuthorizationCode = new OpenApiOAuthFlow
// {
// AuthorizationUrl = new Uri($"https://login.microsoftonline.com/{tenantId}/oauth2/v2.0/authorize"),
// TokenUrl = new Uri($"https://login.microsoftonline.com/{tenantId}/oauth2/v2.0/token"),
// Scopes = new Dictionary<string, string>
// {
// { $"api://{clientId}/access_as_user", "Act as current user" }
// }
// }
// }
//});
setupAction.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme
{
In = ParameterLocation.Header,
Description = "Please enter token",
Name = "Authorization",
Type = SecuritySchemeType.Http,
BearerFormat = "JWT",
Scheme = "bearer"
});
setupAction.AddSecurityRequirement(new OpenApiSecurityRequirement
{
{
new OpenApiSecurityScheme
{
Reference = new OpenApiReference { Type = ReferenceType.SecurityScheme, Id = "Bearer" }
},
new [] { "access_as_user" }
}
});
});
}
public static string GetCleanFilename(this IFormFile file, IFileSystem fs)
{
string untrustedFileName = fs.Path.GetFileName(file.FileName);
if (string.IsNullOrWhiteSpace(untrustedFileName) ||
fs.Path.GetInvalidFileNameChars().Any(untrustedFileName.Contains))
{
throw new ArgumentException("Filename is invalid", nameof(file));
}
return untrustedFileName;
}
}