Release v1.0.0 #16
.editorconfig.envDbInitializer.csDependencyInjection.csnuget.config
.gitea/workflows
.gitignoreApiDto
ApiDto.csproj
Backend.slnDockerfileCommon
AuthRoles.csCacheType.csDatabaseType.csOAuthAction.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.csUserConverter.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
Interfaces
Model
OAuth2
ViewModel
Properties
Security.csprojServices
SqlData
Application
Application.csprojDependencyInjection.cs
Common
Cqrs
Campus
Queries
Discipline
Queries
Faculty
Queries
Group
Queries
LectureHall
Queries
Professor
Queries
GetProfessorDetails
GetProfessorDetailsBySearch
GetProfessorList
Schedule
Interfaces
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
EntityTypeConfigurations
Persistence.csprojUberDbContext.cs@ -5,5 +5,8 @@ internal class OAuthUserExtension
|
|||||||
public string? Message { get; set; }
|
public string? Message { get; set; }
|
||||||
public bool IsSuccess { get; set; }
|
public bool IsSuccess { get; set; }
|
||||||
public required OAuthProvider? Provider { get; set; }
|
public required OAuthProvider? Provider { get; set; }
|
||||||
|
public string? UserAgent { get; set; } = null;
|
||||||
|
public string? Ip { get; set; } = null;
|
||||||
|
public string? Fingerprint { get; set; } = null;
|
||||||
public OAuthUser? User { get; set; }
|
public OAuthUser? User { get; set; }
|
||||||
}
|
}
|
@ -369,8 +369,6 @@ public class OAuthService(ILogger<OAuthService> logger, Dictionary<OAuthProvider
|
|||||||
return (null, "Invalid or expired token.", false, null);
|
return (null, "Invalid or expired token.", false, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
await cache.RemoveAsync(tokenFailedKey, cancellation);
|
|
||||||
|
|
||||||
const string log = "Cache data retrieved for token: {Token}. Fingerprint: {Fingerprint}.";
|
const string log = "Cache data retrieved for token: {Token}. Fingerprint: {Fingerprint}.";
|
||||||
|
|
||||||
if (result.User != null)
|
if (result.User != null)
|
||||||
@ -387,6 +385,38 @@ public class OAuthService(ILogger<OAuthService> logger, Dictionary<OAuthProvider
|
|||||||
else
|
else
|
||||||
logger.LogInformation(log, token, requestInfo.Fingerprint);
|
logger.LogInformation(log, token, requestInfo.Fingerprint);
|
||||||
|
|
||||||
|
if ((!string.IsNullOrEmpty(result.Fingerprint) &&
|
||||||
|
result.Fingerprint != requestInfo.Fingerprint) ||
|
||||||
|
(!string.IsNullOrEmpty(result.UserAgent) &&
|
||||||
|
result.UserAgent != requestInfo.UserAgent &&
|
||||||
|
!string.IsNullOrEmpty(result.Ip)) &&
|
||||||
|
result.Ip != requestInfo.Ip)
|
||||||
|
{
|
||||||
|
logger.LogWarning(
|
||||||
|
"Potential token compromise detected. " +
|
||||||
|
"Token {Token} has been used from different location. " +
|
||||||
|
"Fingerprint: {ExpectedFingerprint} -> {ProvidedFingerprint}, " +
|
||||||
|
"UserAgent: {ExpectedUserAgent} -> {ProvidedUserAgent}, " +
|
||||||
|
"Ip: {ExpectedUserIp} -> {ProvidedIp}",
|
||||||
|
token,
|
||||||
|
result.Fingerprint,
|
||||||
|
requestInfo.Fingerprint,
|
||||||
|
result.UserAgent,
|
||||||
|
requestInfo.UserAgent,
|
||||||
|
result.Ip,
|
||||||
|
requestInfo.Ip);
|
||||||
|
|
||||||
|
await cache.RemoveAsync(token, cancellation);
|
||||||
|
|
||||||
|
return (null, "Invalid or expired token.", false, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
await cache.RemoveAsync(tokenFailedKey, cancellation);
|
||||||
|
|
||||||
|
result.Ip = requestInfo.Ip;
|
||||||
|
result.UserAgent = requestInfo.UserAgent;
|
||||||
|
result.Fingerprint = requestInfo.Fingerprint;
|
||||||
|
|
||||||
return (result.User, result.Message, result.IsSuccess, result.Provider);
|
return (result.User, result.Message, result.IsSuccess, result.Provider);
|
||||||
}
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user