Release v1.0.0 #16
.editorconfig.envnuget.config
.gitea/workflows
.gitignoreApiDto
ApiDto.csproj
Backend.slnDockerfileCommon
AuthRoles.csCacheType.csDatabaseType.csOAuthProvider.csPairPeriodTime.csPasswordPolicy.csTwoFactorAuthentication.cs
Requests
Responses
Endpoint
Backend.httpISaveSettings.cs
README.mdCommon
Attributes
BadRequestResponseAttribute.csCacheMaxAgeAttribute.csLocalhostAttribute.csMaintenanceModeIgnoreAttribute.csNotFoundResponseAttribute.csSwaggerDefaultAttribute.csTokenAuthenticationAttribute.cs
Exceptions
Interfaces
MapperDto
AvailableProvidersConverter.csPairPeriodTimeConverter.csPasswordPolicyConverter.csTwoFactorAuthenticationConverter.cs
Services
Configuration
Core
BackgroundTasks
Middleware
CacheMaxAgeMiddleware.csCookieAuthorizationMiddleware.csCustomExceptionHandlerMiddleware.csJwtRevocationMiddleware.csMaintenanceModeMiddleware.cs
Startup
Model
SwaggerOptions
Validation
Controllers
BaseController.cs
Endpoint.csprojProgram.csConfiguration
V1
AuthController.csCampusController.csDisciplineController.csFacultyController.csGroupController.csImportController.csLectureHallController.csProfessorController.csScheduleController.csSecurityController.cs
WeatherForecastController.csSync
WeatherForecast.cswwwroot/css/swagger
Security
Common
CookieNames.cs
DependencyInjection.csDomain
Caching
CookieOptionsParameters.csOAuth2
OAuthProvider.csOAuthUser.csPasswordPolicy.csRequestContextInfo.csTwoFactorAuthenticator.csUser.csInterfaces
Properties
Security.csprojServices
SqlData
Application
Application.csprojDependencyInjection.cs
Common
Cqrs
Campus/Queries
GetCampusBasicInfoList
CampusBasicInfoDto.csCampusBasicInfoVm.csGetCampusBasicInfoListQuery.csGetCampusBasicInfoListQueryHandler.cs
GetCampusDetails
Discipline/Queries
GetDisciplineDetails
GetDisciplineList
Faculty/Queries/GetFacultyList
Group/Queries
GetGroupDetails
GetGroupList
LectureHall/Queries
GetLectureHallDetails
GetLectureHallList
Professor/Queries
GetProfessorDetails
GetProfessorDetailsBySearch
GetProfessorList
Schedule/Queries/GetScheduleList
Interfaces/DbContexts
Domain
Domain.csproj
Schedule
Migrations
MysqlMigrations
Migrations
20240601023106_InitialMigration.Designer.cs20240601023106_InitialMigration.cs20241027034820_RemoveUnusedRef.Designer.cs20241027034820_RemoveUnusedRef.csUberDbContextModelSnapshot.cs
MysqlMigrations.csprojPsqlMigrations
Migrations
20240601021702_InitialMigration.Designer.cs20240601021702_InitialMigration.cs20241027032753_RemoveUnusedRef.Designer.cs20241027032753_RemoveUnusedRef.csUberDbContextModelSnapshot.cs
PsqlMigrations.csprojSqliteMigrations
Persistence
Common
BaseDbContext.csConfigurationResolver.csDatabaseProvider.csDbContextFactory.csModelBuilderExtensions.cs
Contexts/Schedule
CampusDbContext.csDisciplineDbContext.csFacultyDbContext.csGroupDbContext.csLectureHallDbContext.csLessonAssociationDbContext.csLessonDbContext.csProfessorDbContext.csSpecificWeekDbContext.csTypeOfOccupationDbContext.cs
DbInitializer.csDependencyInjection.csEntityTypeConfigurations
Mark.cs
Persistence.csprojUberDbContext.csMysql/Schedule
CampusConfiguration.csDisciplineConfiguration.csFacultyConfiguration.csGroupConfiguration.csLectureHallConfiguration.csLessonAssociationConfiguration.csLessonConfiguration.csProfessorConfiguration.csSpecificWeekConfiguration.csTypeOfOccupationConfiguration.cs
Postgresql/Schedule
CampusConfiguration.csDisciplineConfiguration.csFacultyConfiguration.csGroupConfiguration.csLectureHallConfiguration.csLessonAssociationConfiguration.csLessonConfiguration.csProfessorConfiguration.csSpecificWeekConfiguration.csTypeOfOccupationConfiguration.cs
Sqlite/Schedule
@ -6,11 +6,29 @@ using Mirea.Api.Security.Common.Interfaces;
|
|||||||
using Mirea.Api.Security.Services;
|
using Mirea.Api.Security.Services;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
namespace Mirea.Api.Security;
|
namespace Mirea.Api.Security;
|
||||||
|
|
||||||
public static class DependencyInjection
|
public static class DependencyInjection
|
||||||
{
|
{
|
||||||
|
private static ReadOnlyMemory<byte> NormalizeKey(string key, int requiredLength)
|
||||||
|
{
|
||||||
|
var keyBytes = Encoding.UTF8.GetBytes(key);
|
||||||
|
|
||||||
|
if (keyBytes.Length < requiredLength)
|
||||||
|
{
|
||||||
|
var normalizedKey = new byte[requiredLength];
|
||||||
|
Array.Copy(keyBytes, normalizedKey, keyBytes.Length);
|
||||||
|
return new ReadOnlyMemory<byte>(normalizedKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (keyBytes.Length > requiredLength)
|
||||||
|
Array.Resize(ref keyBytes, requiredLength);
|
||||||
|
|
||||||
|
return new ReadOnlyMemory<byte>(keyBytes);
|
||||||
|
}
|
||||||
|
|
||||||
public static IServiceCollection AddSecurityServices(this IServiceCollection services, IConfiguration configuration)
|
public static IServiceCollection AddSecurityServices(this IServiceCollection services, IConfiguration configuration)
|
||||||
{
|
{
|
||||||
var saltSize = int.Parse(configuration["SECURITY_SALT_SIZE"]!);
|
var saltSize = int.Parse(configuration["SECURITY_SALT_SIZE"]!);
|
||||||
@ -61,8 +79,13 @@ public static class DependencyInjection
|
|||||||
providers.Add(provider, (clientId, secret));
|
providers.Add(provider, (clientId, secret));
|
||||||
}
|
}
|
||||||
|
|
||||||
services.AddSingleton(provider => new OAuthService(provider.GetRequiredService<ILogger<OAuthService>>(), providers,
|
services.AddSingleton(provider => new OAuthService(
|
||||||
configuration["SECURITY_ENCRYPTION_TOKEN"]!));
|
provider.GetRequiredService<ILogger<OAuthService>>(),
|
||||||
|
providers,
|
||||||
|
provider.GetRequiredService<ICacheService>())
|
||||||
|
{
|
||||||
|
SecretKey = NormalizeKey(configuration["SECURITY_ENCRYPTION_TOKEN"]!, 32)
|
||||||
|
});
|
||||||
|
|
||||||
return services;
|
return services;
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,8 @@ namespace Mirea.Api.Security.Services;
|
|||||||
|
|
||||||
public class OAuthService(ILogger<OAuthService> logger, Dictionary<OAuthProvider, (string ClientId, string Secret)> providers, string secretKey)
|
public class OAuthService(ILogger<OAuthService> logger, Dictionary<OAuthProvider, (string ClientId, string Secret)> providers, string secretKey)
|
||||||
{
|
{
|
||||||
|
public required ReadOnlyMemory<byte> SecretKey { private get; init; }
|
||||||
|
|
||||||
private static readonly Dictionary<OAuthProvider, OAuthProviderUrisData> ProviderData = new()
|
private static readonly Dictionary<OAuthProvider, OAuthProviderUrisData> ProviderData = new()
|
||||||
{
|
{
|
||||||
[OAuthProvider.Google] = new OAuthProviderUrisData
|
[OAuthProvider.Google] = new OAuthProviderUrisData
|
||||||
@ -101,9 +103,9 @@ public class OAuthService(ILogger<OAuthService> logger, Dictionary<OAuthProvider
|
|||||||
return userInfo?.MapToInternalUser();
|
return userInfo?.MapToInternalUser();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string GetHmacString(RequestContextInfo contextInfo, string secretKey)
|
private string GetHmacString(RequestContextInfo contextInfo)
|
||||||
{
|
{
|
||||||
var hmac = new HMACSHA256(Encoding.UTF8.GetBytes(secretKey));
|
var hmac = new HMACSHA256(SecretKey.ToArray());
|
||||||
return Convert.ToBase64String(hmac.ComputeHash(
|
return Convert.ToBase64String(hmac.ComputeHash(
|
||||||
Encoding.UTF8.GetBytes($"{contextInfo.Fingerprint}_{contextInfo.Ip}_{contextInfo.UserAgent}")));
|
Encoding.UTF8.GetBytes($"{contextInfo.Fingerprint}_{contextInfo.Ip}_{contextInfo.UserAgent}")));
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user