-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
1,247 additions
and
986 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,18 +12,26 @@ | |
using Nager.AuthenticationService.WebApi; | ||
using System.Text; | ||
|
||
var users = new UserInfoWithPassword[] | ||
var builder = WebApplication.CreateBuilder(args); | ||
|
||
var initialUser1EmailAddress = builder.Configuration["Authentication:InitialUser:EmailAddress"]; | ||
var initialUser1Password = builder.Configuration["Authentication:InitialUser:Password"]; | ||
|
||
if (string.IsNullOrEmpty(initialUser1EmailAddress) || string.IsNullOrEmpty(initialUser1Password)) | ||
{ | ||
throw new Exception("InitialUser config missing"); | ||
} | ||
|
||
var initialUsers = new UserInfoWithPassword[] | ||
{ | ||
new UserInfoWithPassword | ||
{ | ||
EmailAddress = "[email protected]", | ||
Password = "password", | ||
Roles = new [] { "administrator" } | ||
EmailAddress = initialUser1EmailAddress, | ||
Password = initialUser1Password, | ||
Roles = ["administrator"] | ||
} | ||
}; | ||
|
||
var builder = WebApplication.CreateBuilder(args); | ||
|
||
builder.Services.AddMemoryCache(); | ||
|
||
builder.Services.AddDbContextPool<DatabaseContext>(options => | ||
|
@@ -79,6 +87,35 @@ | |
//var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile); | ||
//configuration.IncludeXmlComments(xmlPath); | ||
|
||
configuration.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme | ||
{ | ||
Description = @"JWT Authorization header using the Bearer scheme. | ||
Enter 'Bearer' [space] and then your token in the text input below. | ||
Example: 'Bearer 12345abcdef'", | ||
Name = "Authorization", | ||
In = ParameterLocation.Header, | ||
Type = SecuritySchemeType.ApiKey, | ||
Scheme = "Bearer" | ||
}); | ||
|
||
configuration.AddSecurityRequirement(new OpenApiSecurityRequirement() | ||
{ | ||
{ | ||
new OpenApiSecurityScheme | ||
{ | ||
Reference = new OpenApiReference | ||
{ | ||
Type = ReferenceType.SecurityScheme, | ||
Id = "Bearer" | ||
}, | ||
Scheme = "oauth2", | ||
Name = "Bearer", | ||
In = ParameterLocation.Header | ||
}, | ||
Array.Empty<string>() | ||
} | ||
}); | ||
|
||
foreach (var filePath in Directory.GetFiles(AppContext.BaseDirectory, "*.xml", SearchOption.TopDirectoryOnly)) | ||
{ | ||
configuration.IncludeXmlComments(filePath); | ||
|
@@ -127,7 +164,7 @@ | |
var services = serviceScope.ServiceProvider; | ||
|
||
var userManagementService = services.GetRequiredService<IUserManagementService>(); | ||
await InitialUserHelper.CreateUsersAsync(users, userManagementService); | ||
await InitialUserHelper.CreateUsersAsync(initialUsers, userManagementService); | ||
} | ||
|
||
app.UseForwardedHeaders(); | ||
|
@@ -146,7 +183,7 @@ | |
|
||
var basePath = "auth"; | ||
var serverUrl = $"{proto}://{host}/{basePath}"; | ||
swagger.Servers = new List<OpenApiServer> { new OpenApiServer { Url = serverUrl } }; | ||
swagger.Servers = [new OpenApiServer { Url = serverUrl }]; | ||
} | ||
}); | ||
}); | ||
|
@@ -172,4 +209,17 @@ | |
app.MapFallbackToFile("index.html"); | ||
app.MapControllers(); | ||
|
||
//using (var serviceScope = app.Services.CreateScope()) | ||
//{ | ||
// var services = serviceScope.ServiceProvider; | ||
|
||
// var userManagementService = services.GetRequiredService<IUserRepository>(); | ||
// var xxx = await userManagementService.GetAsync(o => o.EmailAddress.Equals("[email protected]")); | ||
|
||
// var userAccountService = services.GetRequiredService<IUserAccountService>(); | ||
// await userAccountService.GetMfaInformationAsync("[email protected]"); | ||
|
||
//} | ||
|
||
|
||
app.Run(); |
2 changes: 1 addition & 1 deletion
2
src/Backend/Nager.AuthenticationService.WebApi/appsettings.Development.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,10 @@ | |
"Issuer": "Issuer.PLEASE.CHANGE.ME", | ||
"Audience": "Audience.PLEASE.CHANGE.ME", | ||
"SigningKey": "The.SigningKey.ForUserData.PLEASE.CHANGE.ME" | ||
}, | ||
"InitialUser": { | ||
"EmailAddress": "[email protected]", | ||
"Password": "password" | ||
} | ||
} | ||
} |
Oops, something went wrong.