From bb65ce677f24b276d5cabb20f8b6f975e2e45cdc Mon Sep 17 00:00:00 2001 From: Amin Date: Sat, 21 Nov 2026 00:54:31 +0100 Subject: [PATCH] Refactor project architecture --- ...ntimeAppsAuthenticationBuilderExtension.cs | 5 +- ...enticationRefreshTokenBuilderExtensions.cs | 11 +- ...rificationRequestStoreBuilderExtensions.cs | 9 +- .../RefreshTokenConfiguration.cs | 9 +- .../RefreshTokenModelBuilderExtensions.cs | 6 +- .../Stores}/EfRefreshTokenStore.cs | 11 +- .../VerificationRequestConfiguration.cs | 7 +- ...rificationRequestModelBuilderExtensions.cs | 6 +- .../VerificationSendConfiguration.cs | 7 +- .../Stores}/EfVerificationRequestStore.cs | 11 +- ...hTokenApiEndpointRouteBuilderExtensions.cs | 198 ------------------ .../AuthenticationBuilderExtensions.cs | 7 +- .../RefreshTokenBuilderExtensions.cs | 11 +- .../RuntimeAppsAuthenticationBuilder.cs | 30 ++- ...ccountApiEndpointRouteBuilderExtensions.cs | 92 ++++---- ...sswordApiEndpointRouteBuilderExtensions.cs | 39 ++-- ...hTokenApiEndpointRouteBuilderExtensions.cs | 198 ++++++++++++++++++ .../RoleApiEndpointRouteBuilderExtensions.cs | 9 +- ...eClaimApiEndpointRouteBuilderExtensions.cs | 11 +- .../UserApiEndpointRouteBuilderExtensions.cs | 7 +- ...rClaimApiEndpointRouteBuilderExtensions.cs | 11 +- ...erRoleApiEndpointRouteBuilderExtensions.cs | 9 +- .../Account/Contracts}/IUserAccountService.cs | 7 +- .../Account/Models}/ChangePasswordModel.cs | 2 +- .../Account/Models}/UserLoginModel.cs | 2 +- .../Account/Models}/UserRegisterModel.cs | 4 +- .../Account/Services}/JwtProvider.cs | 9 +- .../Account/Services}/UserAccountService.cs | 15 +- .../IExternalLoginEmailTrustPolicy.cs | 7 +- .../Contracts}/IExternalLoginProvider.cs | 7 +- .../Models}/BaseExternalLoginOption.cs | 2 +- .../Models}/ExternalAuthModel.cs | 2 +- .../Models}/ExternalLoginProviderResult.cs | 4 +- .../Facebook/FacebookAppAccessToken.cs | 2 +- .../Models}/Facebook/FacebookPicture.cs | 2 +- .../Models}/Facebook/FacebookPictureData.cs | 2 +- .../Facebook/FacebookUserAccessTokenData.cs | 2 +- .../FacebookUserAccessTokenValidation.cs | 2 +- .../Models}/Facebook/FacebookUserData.cs | 2 +- .../Models}/FacebookExternalLoginOption.cs | 7 +- .../Models}/GoogleExternalLoginOption.cs | 5 +- .../Models}/MicrosoftExternalLoginOption.cs | 5 +- .../FacebookExternalLoginProvider.cs | 11 +- .../Providers}/GoogleExternalLoginProvider.cs | 13 +- .../MicrosoftExternalLoginProvider.cs | 13 +- .../DefaultExternalLoginEmailTrustPolicy.cs | 11 +- .../Contracts}/IForgotPasswordService.cs | 8 +- .../IForgotPasswordVerificationWorkflow.cs | 9 +- .../Models}/ForgotPasswordMethod.cs | 4 +- .../Models}/ForgotPasswordOptions.cs | 4 +- .../Models}/ForgotPasswordRequestModel.cs | 4 +- .../Models}/ForgotPasswordResponse.cs | 4 +- .../Models}/ResetPasswordModel.cs | 4 +- .../Services}/ForgotPasswordService.cs | 14 +- .../Contracts}/IRefreshTokenService.cs | 7 +- .../Contracts}/IRefreshTokenStore.cs | 7 +- .../RefreshTokens/Models}/RefreshToken.cs | 4 +- .../Models}/RefreshTokenOptions.cs | 4 +- .../Models}/RefreshTokenRequest.cs | 4 +- .../Models}/RefreshTokenSession.cs | 4 +- .../Services}/RefreshTokenRequestLimiter.cs | 7 +- .../Services}/RefreshTokenService.cs | 11 +- .../RefreshTokenStoreStartupValidator.cs | 9 +- .../Contracts}/IRegistrationService.cs | 8 +- .../Registration/Models}/RegisterUserModel.cs | 2 +- .../RegistrationVerificationResponse.cs | 4 +- .../ResendRegistrationVerificationModel.cs | 4 +- .../Models}/VerifyRegistrationModel.cs | 4 +- .../Services}/RegistrationService.cs | 15 +- .../Contracts}/IVerificationCodeGenerator.cs | 7 +- .../Contracts}/IVerificationCodeVerifier.cs | 7 +- .../Contracts}/IVerificationRequestStore.cs | 7 +- .../Contracts}/IVerificationSender.cs | 7 +- .../IVerificationWorkflowService.cs | 8 +- .../Models}/VerificationChannel.cs | 4 +- .../Models}/VerificationCodeContext.cs | 4 +- .../Models}/VerificationOperationResult.cs | 4 +- .../Models}/VerificationOptions.cs | 4 +- .../Models}/VerificationPurpose.cs | 4 +- .../Models}/VerificationRequest.cs | 4 +- .../Models}/VerificationRequestStatus.cs | 4 +- .../Verification/Models}/VerificationSend.cs | 4 +- .../Models}/VerificationTokenGeneratorType.cs | 4 +- .../DataProtectionVerificationCodeVerifier.cs | 10 +- .../RandomVerificationCodeGenerator.cs | 11 +- .../Services}/VerificationHandle.cs | 4 +- .../Services}/VerificationWorkflowService.cs | 13 +- .../Contracts}/IJwtProvider.cs | 5 +- .../Contracts}/IRoleManager.cs | 4 +- .../Contracts}/ISignInManager.cs | 4 +- .../Contracts}/IUserManager.cs | 4 +- .../Contracts}/IUserMapper.cs | 2 +- .../DefaultIdentityUserMapper.cs | 9 +- .../DelegateUserMapper.cs | 5 +- .../Models}/IdentityUserDto.cs | 2 +- .../RuntimeAppsRoleManager.cs | 7 +- .../RuntimeAppsSignInManager.cs | 7 +- .../RuntimeAppsUserManager.cs | 7 +- .../Extensions/IdentityResultExtensions.cs | 4 +- .../Extensions/ResultExtensions.cs | 7 +- .../Extensions/ValidationProblemFactory.cs | 4 +- .../{Model => Shared/Models}/ApiResult.cs | 4 +- .../{Model => Shared/Models}/ClaimDto.cs | 4 +- .../{Model => Shared/Models}/Result.cs | 4 +- .../{Model => Shared/Models}/ResultCode.cs | 2 +- .../{Model => Shared/Models}/Token.cs | 4 +- .../DbInitializer.cs | 9 +- .../Program.cs | 31 ++- .../ApplicationDbContext.cs | 5 +- .../ApplicationDbContextModelSnapshot.cs | 10 +- .../Program.cs | 22 +- .../Program.cs | 22 +- .../Program.cs | 22 +- .../UserDto.cs | 10 +- .../UserMapper.cs | 9 +- .../Program.cs | 18 +- .../Program.cs | 22 +- .../DbInitializer.cs | 9 +- .../Program.cs | 30 ++- .../ApplicationDbContext.cs | 5 +- .../Program.cs | 31 ++- .../Services/MailKitVerificationSender.cs | 18 +- .../EfRefreshTokenStoreTest.cs | 17 +- .../EfVerificationRequestStoreTest.cs | 17 +- .../ExternalLoginEmailTrustPolicyTest.cs | 19 +- .../ForgotPasswordOptionsTest.cs | 12 +- .../ForgotPasswordServiceTest.cs | 26 ++- .../RefreshTokenRegistrationTest.cs | 12 +- .../RefreshTokenServiceTest.cs | 27 ++- .../RegistrationServiceTest.cs | 27 ++- .../UserAccountServiceTest.cs | 50 +++-- .../VerificationPrimitivesTest.cs | 19 +- 132 files changed, 989 insertions(+), 696 deletions(-) rename RuntimeApps.Authentication.EF/{Extensions => DependencyInjection}/RuntimeAppsAuthenticationBuilderExtension.cs (82%) rename RuntimeApps.Authentication.EF/{Extensions => DependencyInjection}/RuntimeAppsAuthenticationRefreshTokenBuilderExtensions.cs (78%) rename RuntimeApps.Authentication.EF/{Extensions => DependencyInjection}/VerificationRequestStoreBuilderExtensions.cs (78%) rename RuntimeApps.Authentication.EF/{Model => Features/RefreshTokens/Configurations}/RefreshTokenConfiguration.cs (89%) rename RuntimeApps.Authentication.EF/{Extensions => Features/RefreshTokens/Configurations}/RefreshTokenModelBuilderExtensions.cs (84%) rename RuntimeApps.Authentication.EF/{Store => Features/RefreshTokens/Stores}/EfRefreshTokenStore.cs (94%) rename RuntimeApps.Authentication.EF/{Model => Features/Verification/Configurations}/VerificationRequestConfiguration.cs (94%) rename RuntimeApps.Authentication.EF/{Extensions => Features/Verification/Configurations}/VerificationRequestModelBuilderExtensions.cs (86%) rename RuntimeApps.Authentication.EF/{Model => Features/Verification/Configurations}/VerificationSendConfiguration.cs (89%) rename RuntimeApps.Authentication.EF/{Store => Features/Verification/Stores}/EfVerificationRequestStore.cs (97%) delete mode 100644 RuntimeApps.Authentication/Controller/RefreshTokenApiEndpointRouteBuilderExtensions.cs rename RuntimeApps.Authentication/{Extensions => DependencyInjection}/AuthenticationBuilderExtensions.cs (79%) rename RuntimeApps.Authentication/{Extensions => DependencyInjection}/RefreshTokenBuilderExtensions.cs (92%) rename RuntimeApps.Authentication/{ => DependencyInjection}/RuntimeAppsAuthenticationBuilder.cs (90%) rename RuntimeApps.Authentication/{Controller => Endpoints/Account}/AccountApiEndpointRouteBuilderExtensions.cs (74%) rename RuntimeApps.Authentication/{Controller => Endpoints/PasswordRecovery}/ForgotPasswordApiEndpointRouteBuilderExtensions.cs (66%) create mode 100644 RuntimeApps.Authentication/Endpoints/RefreshTokens/RefreshTokenApiEndpointRouteBuilderExtensions.cs rename RuntimeApps.Authentication/{Controller => Endpoints/Roles}/RoleApiEndpointRouteBuilderExtensions.cs (92%) rename RuntimeApps.Authentication/{Controller => Endpoints/Roles}/RoleClaimApiEndpointRouteBuilderExtensions.cs (91%) rename RuntimeApps.Authentication/{Controller => Endpoints/Users}/UserApiEndpointRouteBuilderExtensions.cs (88%) rename RuntimeApps.Authentication/{Controller => Endpoints/Users}/UserClaimApiEndpointRouteBuilderExtensions.cs (93%) rename RuntimeApps.Authentication/{Controller => Endpoints/Users}/UserRoleApiEndpointRouteBuilderExtensions.cs (94%) rename RuntimeApps.Authentication/{Interface => Features/Account/Contracts}/IUserAccountService.cs (71%) rename RuntimeApps.Authentication/{Model => Features/Account/Models}/ChangePasswordModel.cs (70%) rename RuntimeApps.Authentication/{Model => Features/Account/Models}/UserLoginModel.cs (67%) rename RuntimeApps.Authentication/{Model => Features/Account/Models}/UserRegisterModel.cs (69%) rename RuntimeApps.Authentication/{Service => Features/Account/Services}/JwtProvider.cs (88%) rename RuntimeApps.Authentication/{Service => Features/Account/Services}/UserAccountService.cs (96%) rename RuntimeApps.Authentication/{Interface => Features/ExternalLogin/Contracts}/IExternalLoginEmailTrustPolicy.cs (56%) rename RuntimeApps.Authentication/{Interface => Features/ExternalLogin/Contracts}/IExternalLoginProvider.cs (57%) rename RuntimeApps.Authentication/{Model => Features/ExternalLogin/Models}/BaseExternalLoginOption.cs (67%) rename RuntimeApps.Authentication/{Model => Features/ExternalLogin/Models}/ExternalAuthModel.cs (65%) rename RuntimeApps.Authentication/{Model => Features/ExternalLogin/Models}/ExternalLoginProviderResult.cs (83%) rename RuntimeApps.Authentication/{Model => Features/ExternalLogin/Models}/Facebook/FacebookAppAccessToken.cs (65%) rename RuntimeApps.Authentication/{Model => Features/ExternalLogin/Models}/Facebook/FacebookPicture.cs (67%) rename RuntimeApps.Authentication/{Model => Features/ExternalLogin/Models}/Facebook/FacebookPictureData.cs (55%) rename RuntimeApps.Authentication/{Model => Features/ExternalLogin/Models}/Facebook/FacebookUserAccessTokenData.cs (80%) rename RuntimeApps.Authentication/{Model => Features/ExternalLogin/Models}/Facebook/FacebookUserAccessTokenValidation.cs (61%) rename RuntimeApps.Authentication/{Model => Features/ExternalLogin/Models}/Facebook/FacebookUserData.cs (83%) rename RuntimeApps.Authentication/{Model => Features/ExternalLogin/Models}/FacebookExternalLoginOption.cs (83%) rename RuntimeApps.Authentication/{Model => Features/ExternalLogin/Models}/GoogleExternalLoginOption.cs (81%) rename RuntimeApps.Authentication/{Model => Features/ExternalLogin/Models}/MicrosoftExternalLoginOption.cs (85%) rename RuntimeApps.Authentication/{Service/ExternalLoginProviders => Features/ExternalLogin/Providers}/FacebookExternalLoginProvider.cs (93%) rename RuntimeApps.Authentication/{Service/ExternalLoginProviders => Features/ExternalLogin/Providers}/GoogleExternalLoginProvider.cs (88%) rename RuntimeApps.Authentication/{Service/ExternalLoginProviders => Features/ExternalLogin/Providers}/MicrosoftExternalLoginProvider.cs (95%) rename RuntimeApps.Authentication/{Service => Features/ExternalLogin/Services}/DefaultExternalLoginEmailTrustPolicy.cs (83%) rename RuntimeApps.Authentication/{Interface => Features/PasswordRecovery/Contracts}/IForgotPasswordService.cs (64%) rename RuntimeApps.Authentication/{Interface => Features/PasswordRecovery/Contracts}/IForgotPasswordVerificationWorkflow.cs (72%) rename RuntimeApps.Authentication/{Model => Features/PasswordRecovery/Models}/ForgotPasswordMethod.cs (66%) rename RuntimeApps.Authentication/{Model => Features/PasswordRecovery/Models}/ForgotPasswordOptions.cs (93%) rename RuntimeApps.Authentication/{Model => Features/PasswordRecovery/Models}/ForgotPasswordRequestModel.cs (79%) rename RuntimeApps.Authentication/{Model => Features/PasswordRecovery/Models}/ForgotPasswordResponse.cs (88%) rename RuntimeApps.Authentication/{Model => Features/PasswordRecovery/Models}/ResetPasswordModel.cs (86%) rename RuntimeApps.Authentication/{Service => Features/PasswordRecovery/Services}/ForgotPasswordService.cs (93%) rename RuntimeApps.Authentication/{Interface => Features/RefreshTokens/Contracts}/IRefreshTokenService.cs (83%) rename RuntimeApps.Authentication/{Interface => Features/RefreshTokens/Contracts}/IRefreshTokenStore.cs (88%) rename RuntimeApps.Authentication/{Model => Features/RefreshTokens/Models}/RefreshToken.cs (94%) rename RuntimeApps.Authentication/{Model => Features/RefreshTokens/Models}/RefreshTokenOptions.cs (94%) rename RuntimeApps.Authentication/{Model => Features/RefreshTokens/Models}/RefreshTokenRequest.cs (87%) rename RuntimeApps.Authentication/{Model => Features/RefreshTokens/Models}/RefreshTokenSession.cs (87%) rename RuntimeApps.Authentication/{Service => Features/RefreshTokens/Services}/RefreshTokenRequestLimiter.cs (91%) rename RuntimeApps.Authentication/{Service => Features/RefreshTokens/Services}/RefreshTokenService.cs (95%) rename RuntimeApps.Authentication/{Service => Features/RefreshTokens/Services}/RefreshTokenStoreStartupValidator.cs (82%) rename RuntimeApps.Authentication/{Interface => Features/Registration/Contracts}/IRegistrationService.cs (75%) rename RuntimeApps.Authentication/{Model => Features/Registration/Models}/RegisterUserModel.cs (71%) rename RuntimeApps.Authentication/{Model => Features/Registration/Models}/RegistrationVerificationResponse.cs (88%) rename RuntimeApps.Authentication/{Model => Features/Registration/Models}/ResendRegistrationVerificationModel.cs (63%) rename RuntimeApps.Authentication/{Model => Features/Registration/Models}/VerifyRegistrationModel.cs (68%) rename RuntimeApps.Authentication/{Service => Features/Registration/Services}/RegistrationService.cs (90%) rename RuntimeApps.Authentication/{Interface => Features/Verification/Contracts}/IVerificationCodeGenerator.cs (68%) rename RuntimeApps.Authentication/{Interface => Features/Verification/Contracts}/IVerificationCodeVerifier.cs (63%) rename RuntimeApps.Authentication/{Interface => Features/Verification/Contracts}/IVerificationRequestStore.cs (93%) rename RuntimeApps.Authentication/{Interface => Features/Verification/Contracts}/IVerificationSender.cs (68%) rename RuntimeApps.Authentication/{Interface => Features/Verification/Contracts}/IVerificationWorkflowService.cs (83%) rename RuntimeApps.Authentication/{Model => Features/Verification/Models}/VerificationChannel.cs (75%) rename RuntimeApps.Authentication/{Model => Features/Verification/Models}/VerificationCodeContext.cs (96%) rename RuntimeApps.Authentication/{Model => Features/Verification/Models}/VerificationOperationResult.cs (90%) rename RuntimeApps.Authentication/{Model => Features/Verification/Models}/VerificationOptions.cs (95%) rename RuntimeApps.Authentication/{Model => Features/Verification/Models}/VerificationPurpose.cs (78%) rename RuntimeApps.Authentication/{Model => Features/Verification/Models}/VerificationRequest.cs (94%) rename RuntimeApps.Authentication/{Model => Features/Verification/Models}/VerificationRequestStatus.cs (66%) rename RuntimeApps.Authentication/{Model => Features/Verification/Models}/VerificationSend.cs (85%) rename RuntimeApps.Authentication/{Model => Features/Verification/Models}/VerificationTokenGeneratorType.cs (72%) rename RuntimeApps.Authentication/{Service => Features/Verification/Services}/DataProtectionVerificationCodeVerifier.cs (92%) rename RuntimeApps.Authentication/{Service => Features/Verification/Services}/RandomVerificationCodeGenerator.cs (77%) rename RuntimeApps.Authentication/{Service => Features/Verification/Services}/VerificationHandle.cs (89%) rename RuntimeApps.Authentication/{Service => Features/Verification/Services}/VerificationWorkflowService.cs (97%) rename RuntimeApps.Authentication/{Interface => Identity/Contracts}/IJwtProvider.cs (55%) rename RuntimeApps.Authentication/{Interface => Identity/Contracts}/IRoleManager.cs (88%) rename RuntimeApps.Authentication/{Interface => Identity/Contracts}/ISignInManager.cs (96%) rename RuntimeApps.Authentication/{Interface => Identity/Contracts}/IUserManager.cs (98%) rename RuntimeApps.Authentication/{Interface => Identity/Contracts}/IUserMapper.cs (91%) rename RuntimeApps.Authentication/{Service => Identity}/DefaultIdentityUserMapper.cs (88%) rename RuntimeApps.Authentication/{Service => Identity}/DelegateUserMapper.cs (89%) rename RuntimeApps.Authentication/{Model => Identity/Models}/IdentityUserDto.cs (88%) rename RuntimeApps.Authentication/{Service => Identity}/RuntimeAppsRoleManager.cs (76%) rename RuntimeApps.Authentication/{Service => Identity}/RuntimeAppsSignInManager.cs (90%) rename RuntimeApps.Authentication/{Service => Identity}/RuntimeAppsUserManager.cs (88%) rename RuntimeApps.Authentication/{ => Shared}/Extensions/IdentityResultExtensions.cs (91%) rename RuntimeApps.Authentication/{ => Shared}/Extensions/ResultExtensions.cs (87%) rename RuntimeApps.Authentication/{ => Shared}/Extensions/ValidationProblemFactory.cs (80%) rename RuntimeApps.Authentication/{Model => Shared/Models}/ApiResult.cs (93%) rename RuntimeApps.Authentication/{Model => Shared/Models}/ClaimDto.cs (81%) rename RuntimeApps.Authentication/{Model => Shared/Models}/Result.cs (96%) rename RuntimeApps.Authentication/{Model => Shared/Models}/ResultCode.cs (77%) rename RuntimeApps.Authentication/{Model => Shared/Models}/Token.cs (95%) diff --git a/RuntimeApps.Authentication.EF/Extensions/RuntimeAppsAuthenticationBuilderExtension.cs b/RuntimeApps.Authentication.EF/DependencyInjection/RuntimeAppsAuthenticationBuilderExtension.cs similarity index 82% rename from RuntimeApps.Authentication.EF/Extensions/RuntimeAppsAuthenticationBuilderExtension.cs rename to RuntimeApps.Authentication.EF/DependencyInjection/RuntimeAppsAuthenticationBuilderExtension.cs index 945cd13..488dae4 100644 --- a/RuntimeApps.Authentication.EF/Extensions/RuntimeAppsAuthenticationBuilderExtension.cs +++ b/RuntimeApps.Authentication.EF/DependencyInjection/RuntimeAppsAuthenticationBuilderExtension.cs @@ -1,7 +1,8 @@ -using Microsoft.AspNetCore.Identity; +using RuntimeApps.Authentication.DependencyInjection; +using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Identity.EntityFrameworkCore; -namespace RuntimeApps.Authentication.EF.Extensions { +namespace RuntimeApps.Authentication.EF.DependencyInjection { public static class RuntimeAppsAuthenticationBuilderExtension { public static RuntimeAppsAuthenticationBuilder AddEfStores(this RuntimeAppsAuthenticationBuilder builder) where TDbContext : IdentityDbContext diff --git a/RuntimeApps.Authentication.EF/Extensions/RuntimeAppsAuthenticationRefreshTokenBuilderExtensions.cs b/RuntimeApps.Authentication.EF/DependencyInjection/RuntimeAppsAuthenticationRefreshTokenBuilderExtensions.cs similarity index 78% rename from RuntimeApps.Authentication.EF/Extensions/RuntimeAppsAuthenticationRefreshTokenBuilderExtensions.cs rename to RuntimeApps.Authentication.EF/DependencyInjection/RuntimeAppsAuthenticationRefreshTokenBuilderExtensions.cs index 9512cd7..852f048 100644 --- a/RuntimeApps.Authentication.EF/Extensions/RuntimeAppsAuthenticationRefreshTokenBuilderExtensions.cs +++ b/RuntimeApps.Authentication.EF/DependencyInjection/RuntimeAppsAuthenticationRefreshTokenBuilderExtensions.cs @@ -1,11 +1,10 @@ using Microsoft.AspNetCore.Identity; using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection.Extensions; -using RuntimeApps.Authentication.EF.Store; -using RuntimeApps.Authentication.Interface; - -namespace RuntimeApps.Authentication.EF.Extensions { +using RuntimeApps.Authentication.DependencyInjection; +using RuntimeApps.Authentication.EF.Features.RefreshTokens.Stores; +using RuntimeApps.Authentication.Features.RefreshTokens.Contracts; +namespace RuntimeApps.Authentication.EF.DependencyInjection { public static class RuntimeAppsAuthenticationRefreshTokenBuilderExtensions { /// Registers the EF-backed refresh-token store for an Identity DbContext. public static RuntimeAppsAuthenticationBuilder AddEfRefreshTokenStore( @@ -19,4 +18,4 @@ public static RuntimeAppsAuthenticationBuilder AddEfRefreshT return builder; } } -} \ No newline at end of file +} diff --git a/RuntimeApps.Authentication.EF/Extensions/VerificationRequestStoreBuilderExtensions.cs b/RuntimeApps.Authentication.EF/DependencyInjection/VerificationRequestStoreBuilderExtensions.cs similarity index 78% rename from RuntimeApps.Authentication.EF/Extensions/VerificationRequestStoreBuilderExtensions.cs rename to RuntimeApps.Authentication.EF/DependencyInjection/VerificationRequestStoreBuilderExtensions.cs index 2112e67..69ac4e3 100644 --- a/RuntimeApps.Authentication.EF/Extensions/VerificationRequestStoreBuilderExtensions.cs +++ b/RuntimeApps.Authentication.EF/DependencyInjection/VerificationRequestStoreBuilderExtensions.cs @@ -1,10 +1,9 @@ using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection.Extensions; -using RuntimeApps.Authentication.EF.Store; -using RuntimeApps.Authentication.Interface; - -namespace RuntimeApps.Authentication.EF.Extensions { +using RuntimeApps.Authentication.EF.Features.Verification.Stores; +using RuntimeApps.Authentication.Features.Verification.Contracts; +namespace RuntimeApps.Authentication.EF.DependencyInjection { public static class VerificationRequestStoreBuilderExtensions { /// Registers the EF Core verification-request store. public static IServiceCollection AddVerificationRequestStore(this IServiceCollection services) @@ -15,4 +14,4 @@ public static IServiceCollection AddVerificationRequestStore(t return services; } } -} \ No newline at end of file +} diff --git a/RuntimeApps.Authentication.EF/Model/RefreshTokenConfiguration.cs b/RuntimeApps.Authentication.EF/Features/RefreshTokens/Configurations/RefreshTokenConfiguration.cs similarity index 89% rename from RuntimeApps.Authentication.EF/Model/RefreshTokenConfiguration.cs rename to RuntimeApps.Authentication.EF/Features/RefreshTokens/Configurations/RefreshTokenConfiguration.cs index 4b56d88..bf8dc8d 100644 --- a/RuntimeApps.Authentication.EF/Model/RefreshTokenConfiguration.cs +++ b/RuntimeApps.Authentication.EF/Features/RefreshTokens/Configurations/RefreshTokenConfiguration.cs @@ -1,10 +1,9 @@ using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Builders; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using RuntimeApps.Authentication.Model; - -namespace RuntimeApps.Authentication.EF.Model { - public sealed class RefreshTokenConfiguration : IEntityTypeConfiguration> +using RuntimeApps.Authentication.Features.RefreshTokens.Models; +namespace RuntimeApps.Authentication.EF.Features.RefreshTokens.Configurations { + public sealed class RefreshTokenConfiguration: IEntityTypeConfiguration> where TKey : IEquatable { public void Configure(EntityTypeBuilder> builder) { builder.ToTable("AuthenticationRefreshTokens"); @@ -32,4 +31,4 @@ public void Configure(EntityTypeBuilder> builder) { builder.HasIndex(token => token.ExpiresAt); } } -} \ No newline at end of file +} diff --git a/RuntimeApps.Authentication.EF/Extensions/RefreshTokenModelBuilderExtensions.cs b/RuntimeApps.Authentication.EF/Features/RefreshTokens/Configurations/RefreshTokenModelBuilderExtensions.cs similarity index 84% rename from RuntimeApps.Authentication.EF/Extensions/RefreshTokenModelBuilderExtensions.cs rename to RuntimeApps.Authentication.EF/Features/RefreshTokens/Configurations/RefreshTokenModelBuilderExtensions.cs index c15652c..30b3d68 100644 --- a/RuntimeApps.Authentication.EF/Extensions/RefreshTokenModelBuilderExtensions.cs +++ b/RuntimeApps.Authentication.EF/Features/RefreshTokens/Configurations/RefreshTokenModelBuilderExtensions.cs @@ -1,7 +1,5 @@ using Microsoft.EntityFrameworkCore; -using RuntimeApps.Authentication.EF.Model; - -namespace RuntimeApps.Authentication.EF.Extensions { +namespace RuntimeApps.Authentication.EF.Features.RefreshTokens.Configurations { public static class RefreshTokenModelBuilderExtensions { /// Adds the refresh-token entity to the consumer application's DbContext model. public static ModelBuilder AddRefreshTokenEntity(this ModelBuilder modelBuilder) @@ -11,4 +9,4 @@ public static ModelBuilder AddRefreshTokenEntity(this ModelBuilder modelBu return modelBuilder; } } -} \ No newline at end of file +} diff --git a/RuntimeApps.Authentication.EF/Store/EfRefreshTokenStore.cs b/RuntimeApps.Authentication.EF/Features/RefreshTokens/Stores/EfRefreshTokenStore.cs similarity index 94% rename from RuntimeApps.Authentication.EF/Store/EfRefreshTokenStore.cs rename to RuntimeApps.Authentication.EF/Features/RefreshTokens/Stores/EfRefreshTokenStore.cs index 6739b83..833f46c 100644 --- a/RuntimeApps.Authentication.EF/Store/EfRefreshTokenStore.cs +++ b/RuntimeApps.Authentication.EF/Features/RefreshTokens/Stores/EfRefreshTokenStore.cs @@ -1,12 +1,11 @@ using Microsoft.EntityFrameworkCore; -using RuntimeApps.Authentication.Interface; -using RuntimeApps.Authentication.Model; - -namespace RuntimeApps.Authentication.EF.Store { +using RuntimeApps.Authentication.Features.RefreshTokens.Contracts; +using RuntimeApps.Authentication.Features.RefreshTokens.Models; +namespace RuntimeApps.Authentication.EF.Features.RefreshTokens.Stores { /// /// EF Core store. Atomic rotation requires a relational provider with transaction support. /// - public sealed class EfRefreshTokenStore : IRefreshTokenStore + public sealed class EfRefreshTokenStore: IRefreshTokenStore where TDbContext : DbContext where TKey : IEquatable { private readonly TDbContext _dbContext; @@ -98,4 +97,4 @@ await _dbContext.Set>() .Where(token => object.Equals(token.UserId, userId) && token.RevokedAt == null) .ExecuteUpdateAsync(setters => setters.SetProperty(token => token.RevokedAt, revokedAt), cancellationToken); } -} \ No newline at end of file +} diff --git a/RuntimeApps.Authentication.EF/Model/VerificationRequestConfiguration.cs b/RuntimeApps.Authentication.EF/Features/Verification/Configurations/VerificationRequestConfiguration.cs similarity index 94% rename from RuntimeApps.Authentication.EF/Model/VerificationRequestConfiguration.cs rename to RuntimeApps.Authentication.EF/Features/Verification/Configurations/VerificationRequestConfiguration.cs index e73441a..991071e 100644 --- a/RuntimeApps.Authentication.EF/Model/VerificationRequestConfiguration.cs +++ b/RuntimeApps.Authentication.EF/Features/Verification/Configurations/VerificationRequestConfiguration.cs @@ -1,9 +1,8 @@ using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Builders; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using RuntimeApps.Authentication.Model; - -namespace RuntimeApps.Authentication.EF.Model { +using RuntimeApps.Authentication.Features.Verification.Models; +namespace RuntimeApps.Authentication.EF.Features.Verification.Configurations { public sealed class VerificationRequestConfiguration : IEntityTypeConfiguration> where TKey : IEquatable { public void Configure(EntityTypeBuilder> builder) { @@ -35,4 +34,4 @@ public void Configure(EntityTypeBuilder> builder) { builder.HasIndex(request => new { request.Status, request.ExpiresAt }); } } -} \ No newline at end of file +} diff --git a/RuntimeApps.Authentication.EF/Extensions/VerificationRequestModelBuilderExtensions.cs b/RuntimeApps.Authentication.EF/Features/Verification/Configurations/VerificationRequestModelBuilderExtensions.cs similarity index 86% rename from RuntimeApps.Authentication.EF/Extensions/VerificationRequestModelBuilderExtensions.cs rename to RuntimeApps.Authentication.EF/Features/Verification/Configurations/VerificationRequestModelBuilderExtensions.cs index b6fa175..74df79c 100644 --- a/RuntimeApps.Authentication.EF/Extensions/VerificationRequestModelBuilderExtensions.cs +++ b/RuntimeApps.Authentication.EF/Features/Verification/Configurations/VerificationRequestModelBuilderExtensions.cs @@ -1,7 +1,5 @@ using Microsoft.EntityFrameworkCore; -using RuntimeApps.Authentication.EF.Model; - -namespace RuntimeApps.Authentication.EF.Extensions { +namespace RuntimeApps.Authentication.EF.Features.Verification.Configurations { public static class VerificationRequestModelBuilderExtensions { /// Adds the verification request and delivery-rate-limit entities to the consumer DbContext. public static ModelBuilder AddVerificationRequestEntity(this ModelBuilder modelBuilder) @@ -12,4 +10,4 @@ public static ModelBuilder AddVerificationRequestEntity(this ModelBuilder return modelBuilder; } } -} \ No newline at end of file +} diff --git a/RuntimeApps.Authentication.EF/Model/VerificationSendConfiguration.cs b/RuntimeApps.Authentication.EF/Features/Verification/Configurations/VerificationSendConfiguration.cs similarity index 89% rename from RuntimeApps.Authentication.EF/Model/VerificationSendConfiguration.cs rename to RuntimeApps.Authentication.EF/Features/Verification/Configurations/VerificationSendConfiguration.cs index 97bc76d..abf31fa 100644 --- a/RuntimeApps.Authentication.EF/Model/VerificationSendConfiguration.cs +++ b/RuntimeApps.Authentication.EF/Features/Verification/Configurations/VerificationSendConfiguration.cs @@ -1,9 +1,8 @@ using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Builders; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using RuntimeApps.Authentication.Model; - -namespace RuntimeApps.Authentication.EF.Model { +using RuntimeApps.Authentication.Features.Verification.Models; +namespace RuntimeApps.Authentication.EF.Features.Verification.Configurations { public sealed class VerificationSendConfiguration : IEntityTypeConfiguration { public void Configure(EntityTypeBuilder builder) { builder.ToTable("AuthenticationVerificationSends"); @@ -22,4 +21,4 @@ public void Configure(EntityTypeBuilder builder) { }); } } -} \ No newline at end of file +} diff --git a/RuntimeApps.Authentication.EF/Store/EfVerificationRequestStore.cs b/RuntimeApps.Authentication.EF/Features/Verification/Stores/EfVerificationRequestStore.cs similarity index 97% rename from RuntimeApps.Authentication.EF/Store/EfVerificationRequestStore.cs rename to RuntimeApps.Authentication.EF/Features/Verification/Stores/EfVerificationRequestStore.cs index 86ec957..41b2091 100644 --- a/RuntimeApps.Authentication.EF/Store/EfVerificationRequestStore.cs +++ b/RuntimeApps.Authentication.EF/Features/Verification/Stores/EfVerificationRequestStore.cs @@ -1,14 +1,13 @@ using System.Data; using Microsoft.EntityFrameworkCore; -using RuntimeApps.Authentication.Interface; -using RuntimeApps.Authentication.Model; - -namespace RuntimeApps.Authentication.EF.Store { +using RuntimeApps.Authentication.Features.Verification.Contracts; +using RuntimeApps.Authentication.Features.Verification.Models; +namespace RuntimeApps.Authentication.EF.Features.Verification.Stores { /// /// Relational EF Core implementation. Conditional updates and serializable transactions protect /// request state transitions and destination-level send limits against concurrent requests. /// - public sealed class EfVerificationRequestStore : IVerificationRequestStore + public sealed class EfVerificationRequestStore: IVerificationRequestStore where TDbContext : DbContext where TKey : IEquatable { private readonly TDbContext _dbContext; @@ -234,4 +233,4 @@ private void EnsureRelational() { throw new NotSupportedException("Atomic verification-request operations require a relational EF Core provider."); } } -} \ No newline at end of file +} diff --git a/RuntimeApps.Authentication/Controller/RefreshTokenApiEndpointRouteBuilderExtensions.cs b/RuntimeApps.Authentication/Controller/RefreshTokenApiEndpointRouteBuilderExtensions.cs deleted file mode 100644 index 798be74..0000000 --- a/RuntimeApps.Authentication/Controller/RefreshTokenApiEndpointRouteBuilderExtensions.cs +++ /dev/null @@ -1,198 +0,0 @@ -using System.Net.Http.Json; -using Microsoft.AspNetCore.Authentication; -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Identity; -using Microsoft.AspNetCore.Routing; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Options; -using RuntimeApps.Authentication.Interface; -using RuntimeApps.Authentication.Model; -using RuntimeApps.Authentication.Service; - -namespace RuntimeApps.Authentication.Controller { - public static class RefreshTokenApiEndpointRouteBuilderExtensions { - /// - /// Maps refresh, current-session logout, and logout-all endpoints. This is called automatically - /// by MapLoginApi when AddRefreshToken has registered the refresh-token service. - /// - public static IEndpointRouteBuilder MapRefreshTokenApi(this IEndpointRouteBuilder endpoints) - where TUser : IdentityUser - where TKey : IEquatable { - var routes = endpoints.MapGroup(""); - - routes.MapPost("refresh", async Task (HttpContext context, - IUserManager userManager, - ISignInManager signInManager, - IRefreshTokenService refreshTokenService, - IRefreshTokenRequestLimiter requestLimiter, - IServiceProvider services, - IAuthenticationSchemeProvider schemeProvider, - IAuthenticationHandlerProvider handlerProvider, - IOptions options, - IOptions verificationOptions) => { - if(!await requestLimiter.IsAllowedAsync(context, context.RequestAborted)) - return Results.StatusCode(StatusCodes.Status429TooManyRequests); - - var isCookie = await HasCookieSignInHandlerAsync(context, schemeProvider, handlerProvider); - RefreshTokenRequest request = null; - if(!isCookie && context.Request.HasJsonContentType()) - request = await context.Request.ReadFromJsonAsync(context.RequestAborted); - if(isCookie && !IsAllowedOrigin(context, options.Value)) - return Results.StatusCode(StatusCodes.Status403Forbidden); - - var suppliedToken = isCookie - ? context.Request.Cookies[options.Value.CookieName] - : request?.RefreshToken; - - var session = await refreshTokenService.RotateAsync(suppliedToken, context.RequestAborted); - if(session == null) - return Results.Unauthorized(); - - var user = await userManager.FindByIdAsync(Convert.ToString(session.UserId, System.Globalization.CultureInfo.InvariantCulture)); - if(user == null) { - await refreshTokenService.RevokeAsync(session.RefreshToken, context.RequestAborted); - return Results.Unauthorized(); - } - - var isLockedOut = await userManager.IsLockedOutAsync(user); - var hasExternalLogin = (await userManager.GetLoginsAsync(user)).Count > 0; - var emailPolicyAllowsSignIn = user.EmailConfirmed || - (hasExternalLogin && !verificationOptions.Value.RequireEmailVerificationForExternalLogins); - if(isLockedOut || !emailPolicyAllowsSignIn || - (user.EmailConfirmed && !await signInManager.CanSignInAsync(user))) { - await refreshTokenService.RevokeAsync(session.RefreshToken, context.RequestAborted); - return Results.Unauthorized(); - } - - try { - if(isCookie) { - await signInManager.SignInAsync(user, true); - AppendRefreshCookie(context, options.Value, session.RefreshToken, session.ExpiresAt); - return Results.NoContent(); - } - - var jwtProvider = services.GetService>(); - if(jwtProvider == null) { - await refreshTokenService.RevokeAsync(session.RefreshToken, CancellationToken.None); - return Results.Problem("JWT authentication is not configured.", statusCode: StatusCodes.Status500InternalServerError); - } - - var accessToken = await jwtProvider.GenerateTokenAsync(user); - accessToken.RefreshToken = session.RefreshToken; - accessToken.RefreshTokenExpireDate = session.ExpiresAt; - accessToken.SessionId = session.SessionId; - return Results.Ok(accessToken); - } - catch { - await refreshTokenService.RevokeAsync(session.RefreshToken, CancellationToken.None); - throw; - } - }) - .Accepts(true, "application/json") - .WithSummary("Refresh the current session") - .WithDescription("JWT clients send a RefreshTokenRequest JSON body. Cookie clients send the refresh-token cookie; the JSON body is optional for cookie authentication."); - - routes.MapPost("logout", async Task (HttpContext context, - IRefreshTokenService refreshTokenService, - IOptions options) => { - var isCookie = await HasCookieSignInHandlerAsync(context, - context.RequestServices.GetRequiredService(), - context.RequestServices.GetRequiredService()); - RefreshTokenRequest request = null; - if(!isCookie && context.Request.HasJsonContentType()) - request = await context.Request.ReadFromJsonAsync(context.RequestAborted); - if(isCookie && !IsAllowedOrigin(context, options.Value)) - return Results.StatusCode(StatusCodes.Status403Forbidden); - - var token = isCookie - ? context.Request.Cookies[options.Value.CookieName] - : request?.RefreshToken; - await refreshTokenService.RevokeAsync(token, context.RequestAborted); - if(isCookie) - await context.SignOutAsync(); - context.Response.Cookies.Delete(options.Value.CookieName, new CookieOptions { - Path = options.Value.CookiePath, - Secure = options.Value.CookieSecure, - HttpOnly = true, - SameSite = options.Value.CookieSameSite - }); - return Results.NoContent(); - }) - .Accepts(true, "application/json") - .WithSummary("Log out the current session") - .WithDescription("JWT clients send a RefreshTokenRequest JSON body. Cookie clients send the refresh-token cookie; the JSON body is optional for cookie authentication."); - - routes.MapPost("logout/all", async Task (HttpContext context, - IUserManager userManager, - IRefreshTokenService refreshTokenService, - IOptions options) => { - var user = await userManager.GetUserAsync(context.User); - if(user == null) - return Results.Unauthorized(); - - var isCookie = await HasCookieSignInHandlerAsync(context, - context.RequestServices.GetRequiredService(), - context.RequestServices.GetRequiredService()); - if(isCookie && !IsAllowedOrigin(context, options.Value)) - return Results.StatusCode(StatusCodes.Status403Forbidden); - - await refreshTokenService.RevokeAllAsync(user.Id, context.RequestAborted); - if(isCookie) - await context.SignOutAsync(); - context.Response.Cookies.Delete(options.Value.CookieName, new CookieOptions { - Path = options.Value.CookiePath, - Secure = options.Value.CookieSecure, - HttpOnly = true, - SameSite = options.Value.CookieSameSite - }); - return Results.NoContent(); - }).RequireAuthorization(); - - return endpoints; - } - - private static async Task HasCookieSignInHandlerAsync( - HttpContext context, - IAuthenticationSchemeProvider schemeProvider, - IAuthenticationHandlerProvider handlerProvider) { - var scheme = await schemeProvider.GetDefaultSignInSchemeAsync(); - if(scheme == null) - return false; - - var handler = await handlerProvider.GetHandlerAsync(context, scheme.Name); - return handler is IAuthenticationSignInHandler; - } - - private static bool IsAllowedOrigin(HttpContext context, RefreshTokenOptions options) { - var origin = context.Request.Headers["Origin"].ToString(); - if(!Uri.TryCreate(origin, UriKind.Absolute, out var originUri) || - (originUri.Scheme != Uri.UriSchemeHttp && originUri.Scheme != Uri.UriSchemeHttps) || - originUri.AbsolutePath != "/" || !string.IsNullOrEmpty(originUri.Query) || - !string.IsNullOrEmpty(originUri.Fragment)) - return false; - - var normalizedOrigin = originUri.GetLeftPart(UriPartial.Authority).TrimEnd('/'); - var requestOrigin = $"{context.Request.Scheme}://{context.Request.Host}".TrimEnd('/'); - if(string.Equals(normalizedOrigin, requestOrigin, StringComparison.OrdinalIgnoreCase)) - return true; - - return options.AllowedOrigins?.Any(allowed => - string.Equals(allowed?.TrimEnd('/'), normalizedOrigin, StringComparison.OrdinalIgnoreCase)) == true; - } - - private static void AppendRefreshCookie( - HttpContext context, - RefreshTokenOptions options, - string refreshToken, - DateTimeOffset expiresAt) { - context.Response.Cookies.Append(options.CookieName, refreshToken, new CookieOptions { - HttpOnly = true, - Secure = options.CookieSecure, - SameSite = options.CookieSameSite, - Path = options.CookiePath, - Expires = expiresAt - }); - } - } -} \ No newline at end of file diff --git a/RuntimeApps.Authentication/Extensions/AuthenticationBuilderExtensions.cs b/RuntimeApps.Authentication/DependencyInjection/AuthenticationBuilderExtensions.cs similarity index 79% rename from RuntimeApps.Authentication/Extensions/AuthenticationBuilderExtensions.cs rename to RuntimeApps.Authentication/DependencyInjection/AuthenticationBuilderExtensions.cs index b9afd39..9688b81 100644 --- a/RuntimeApps.Authentication/Extensions/AuthenticationBuilderExtensions.cs +++ b/RuntimeApps.Authentication/DependencyInjection/AuthenticationBuilderExtensions.cs @@ -1,12 +1,7 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.Identity; -namespace RuntimeApps.Authentication.Extensions { +namespace RuntimeApps.Authentication.DependencyInjection { public static class AuthenticationBuilderExtensions { public static RuntimeAppsAuthenticationBuilder AddRuntimeAppsAuthentication(this AuthenticationBuilder builder) where TUser : IdentityUser, new() diff --git a/RuntimeApps.Authentication/Extensions/RefreshTokenBuilderExtensions.cs b/RuntimeApps.Authentication/DependencyInjection/RefreshTokenBuilderExtensions.cs similarity index 92% rename from RuntimeApps.Authentication/Extensions/RefreshTokenBuilderExtensions.cs rename to RuntimeApps.Authentication/DependencyInjection/RefreshTokenBuilderExtensions.cs index e82fa3c..7d97244 100644 --- a/RuntimeApps.Authentication/Extensions/RefreshTokenBuilderExtensions.cs +++ b/RuntimeApps.Authentication/DependencyInjection/RefreshTokenBuilderExtensions.cs @@ -1,11 +1,10 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection.Extensions; using Microsoft.Extensions.Hosting; -using RuntimeApps.Authentication.Interface; -using RuntimeApps.Authentication.Model; -using RuntimeApps.Authentication.Service; - -namespace RuntimeApps.Authentication.Extensions { +using RuntimeApps.Authentication.Features.RefreshTokens.Contracts; +using RuntimeApps.Authentication.Features.RefreshTokens.Models; +using RuntimeApps.Authentication.Features.RefreshTokens.Services; +namespace RuntimeApps.Authentication.DependencyInjection { public static class RefreshTokenBuilderExtensions { /// /// Enables refresh-token management. A store must also be registered, either by the EF @@ -51,4 +50,4 @@ public static RuntimeAppsAuthenticationBuilder AddRefreshTok return builder; } } -} \ No newline at end of file +} diff --git a/RuntimeApps.Authentication/RuntimeAppsAuthenticationBuilder.cs b/RuntimeApps.Authentication/DependencyInjection/RuntimeAppsAuthenticationBuilder.cs similarity index 90% rename from RuntimeApps.Authentication/RuntimeAppsAuthenticationBuilder.cs rename to RuntimeApps.Authentication/DependencyInjection/RuntimeAppsAuthenticationBuilder.cs index 073fb5b..885cdb3 100644 --- a/RuntimeApps.Authentication/RuntimeAppsAuthenticationBuilder.cs +++ b/RuntimeApps.Authentication/DependencyInjection/RuntimeAppsAuthenticationBuilder.cs @@ -1,14 +1,27 @@ -using Microsoft.AspNetCore.Authentication; +using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.Authentication.JwtBearer; using Microsoft.AspNetCore.Identity; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection.Extensions; -using RuntimeApps.Authentication.Interface; -using RuntimeApps.Authentication.Model; -using RuntimeApps.Authentication.Service; -using RuntimeApps.Authentication.Service.ExternalLoginProviders; - -namespace RuntimeApps.Authentication { +using RuntimeApps.Authentication.Features.Account.Contracts; +using RuntimeApps.Authentication.Features.Account.Services; +using RuntimeApps.Authentication.Features.ExternalLogin.Contracts; +using RuntimeApps.Authentication.Features.ExternalLogin.Models; +using RuntimeApps.Authentication.Features.ExternalLogin.Providers; +using RuntimeApps.Authentication.Features.ExternalLogin.Services; +using RuntimeApps.Authentication.Features.PasswordRecovery.Contracts; +using RuntimeApps.Authentication.Features.PasswordRecovery.Models; +using RuntimeApps.Authentication.Features.PasswordRecovery.Services; +using RuntimeApps.Authentication.Features.Registration.Contracts; +using RuntimeApps.Authentication.Features.Registration.Services; +using RuntimeApps.Authentication.Features.Verification.Contracts; +using RuntimeApps.Authentication.Features.Verification.Models; +using RuntimeApps.Authentication.Features.Verification.Services; +using RuntimeApps.Authentication.Identity; +using RuntimeApps.Authentication.Identity.Contracts; +using RuntimeApps.Authentication.Identity.Models; + +namespace RuntimeApps.Authentication.DependencyInjection { public class RuntimeAppsAuthenticationBuilder where TUser : IdentityUser, new() where TRole : IdentityRole @@ -89,8 +102,7 @@ public RuntimeAppsAuthenticationBuilder AddForgotPassword( Services.AddOptions() .Configure(options => configureOptions?.Invoke(options)) .Validate(options => { - try { options.Validate(); return true; } - catch(InvalidOperationException) { return false; } + try { options.Validate(); return true; } catch(InvalidOperationException) { return false; } }, "Forgot-password options are invalid.") .ValidateOnStart(); // Password-reset operations use ASP.NET Core Identity's token provider. Register diff --git a/RuntimeApps.Authentication/Controller/AccountApiEndpointRouteBuilderExtensions.cs b/RuntimeApps.Authentication/Endpoints/Account/AccountApiEndpointRouteBuilderExtensions.cs similarity index 74% rename from RuntimeApps.Authentication/Controller/AccountApiEndpointRouteBuilderExtensions.cs rename to RuntimeApps.Authentication/Endpoints/Account/AccountApiEndpointRouteBuilderExtensions.cs index e6eece3..70edc21 100644 --- a/RuntimeApps.Authentication/Controller/AccountApiEndpointRouteBuilderExtensions.cs +++ b/RuntimeApps.Authentication/Endpoints/Account/AccountApiEndpointRouteBuilderExtensions.cs @@ -1,4 +1,4 @@ -using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.HttpResults; @@ -6,11 +6,19 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Routing; using Microsoft.Extensions.DependencyInjection; -using RuntimeApps.Authentication.Extensions; -using RuntimeApps.Authentication.Interface; -using RuntimeApps.Authentication.Model; - -namespace RuntimeApps.Authentication.Controller { +using RuntimeApps.Authentication.Endpoints.RefreshTokens; +using RuntimeApps.Authentication.Features.Account.Contracts; +using RuntimeApps.Authentication.Features.Account.Models; +using RuntimeApps.Authentication.Features.ExternalLogin.Contracts; +using RuntimeApps.Authentication.Features.ExternalLogin.Models; +using RuntimeApps.Authentication.Features.RefreshTokens.Contracts; +using RuntimeApps.Authentication.Features.Registration.Contracts; +using RuntimeApps.Authentication.Features.Registration.Models; +using RuntimeApps.Authentication.Features.Verification.Contracts; +using RuntimeApps.Authentication.Identity.Contracts; +using RuntimeApps.Authentication.Shared.Extensions; +using RuntimeApps.Authentication.Shared.Models; +namespace RuntimeApps.Authentication.Endpoints.Account { public static class AccountApiEndpointRouteBuilderExtensions { public static IEndpointRouteBuilder MapLoginApi(this IEndpointRouteBuilder endpoints) where TUser : IdentityUser @@ -72,44 +80,44 @@ public static IEndpointRouteBuilder MapRegisterApi(this I IRegistrationService registrationService, [FromServices] IUserMapper mapper, HttpContext httpContext) => { - if(user?.UserInfo == null) - return ValidationProblemFactory.CreateValidationProblem("InvalidRegistration", "User information is required."); + if(user?.UserInfo == null) + return ValidationProblemFactory.CreateValidationProblem("InvalidRegistration", "User information is required."); - var result = await registrationService.RegisterAsync( - mapper.ToUser(user.UserInfo), user.Password, httpContext.RequestAborted); - if(!result.Succeeded) - return result.CreateValidationProblem(); - return TypedResults.Accepted((string)null, result); - }); + var result = await registrationService.RegisterAsync( + mapper.ToUser(user.UserInfo), user.Password, httpContext.RequestAborted); + if(!result.Succeeded) + return result.CreateValidationProblem(); + return TypedResults.Accepted((string)null, result); + }); routeGroup.MapPost("register/verify", async Task>, ValidationProblem>> ( [FromBody] VerifyRegistrationModel request, IRegistrationService registrationService, [FromServices] IUserMapper mapper, HttpContext httpContext) => { - if(request == null) - return ValidationProblemFactory.CreateValidationProblem("InvalidVerification", "Verification handle and code are required."); + if(request == null) + return ValidationProblemFactory.CreateValidationProblem("InvalidVerification", "Verification handle and code are required."); - var result = await registrationService.VerifyAsync( - request.VerificationHandle, request.Code, httpContext.RequestAborted); - if(!result.Succeeded) - return result.CreateValidationProblem(); - return TypedResults.Ok(MapResult(result, mapper)); - }); + var result = await registrationService.VerifyAsync( + request.VerificationHandle, request.Code, httpContext.RequestAborted); + if(!result.Succeeded) + return result.CreateValidationProblem(); + return TypedResults.Ok(MapResult(result, mapper)); + }); routeGroup.MapPost("register/resend", async Task>, ValidationProblem>> ( [FromBody] ResendRegistrationVerificationModel request, IRegistrationService registrationService, HttpContext httpContext) => { - if(request == null) - return ValidationProblemFactory.CreateValidationProblem("InvalidVerification", "Verification handle is required."); + if(request == null) + return ValidationProblemFactory.CreateValidationProblem("InvalidVerification", "Verification handle is required."); - var result = await registrationService.ResendAsync( - request.VerificationHandle, httpContext.RequestAborted); - if(!result.Succeeded) - return result.CreateValidationProblem(); - return TypedResults.Accepted((string)null, result); - }); + var result = await registrationService.ResendAsync( + request.VerificationHandle, httpContext.RequestAborted); + if(!result.Succeeded) + return result.CreateValidationProblem(); + return TypedResults.Accepted((string)null, result); + }); return endpoints; } @@ -139,21 +147,21 @@ public static IEndpointRouteBuilder MapAdminUserApi( [FromBody] RegisterUserModel request, IUserManager userManager, [FromServices] IUserMapper mapper) => { - if(request?.UserInfo == null || string.IsNullOrEmpty(request.Password)) - return ValidationProblemFactory.CreateValidationProblem( - "InvalidUser", "User information and password are required."); + if(request?.UserInfo == null || string.IsNullOrEmpty(request.Password)) + return ValidationProblemFactory.CreateValidationProblem( + "InvalidUser", "User information and password are required."); - var user = mapper.ToUser(request.UserInfo); - if(string.IsNullOrWhiteSpace(user.UserName)) - user.UserName = user.Email; - user.EmailConfirmed = true; + var user = mapper.ToUser(request.UserInfo); + if(string.IsNullOrWhiteSpace(user.UserName)) + user.UserName = user.Email; + user.EmailConfirmed = true; - var result = await userManager.CreateAsync(user, request.Password); - if(!result.Succeeded) - return result.CreateValidationProblem(); + var result = await userManager.CreateAsync(user, request.Password); + if(!result.Succeeded) + return result.CreateValidationProblem(); - return TypedResults.Ok(mapper.ToDto(user)); - }); + return TypedResults.Ok(mapper.ToDto(user)); + }); return endpoints; } diff --git a/RuntimeApps.Authentication/Controller/ForgotPasswordApiEndpointRouteBuilderExtensions.cs b/RuntimeApps.Authentication/Endpoints/PasswordRecovery/ForgotPasswordApiEndpointRouteBuilderExtensions.cs similarity index 66% rename from RuntimeApps.Authentication/Controller/ForgotPasswordApiEndpointRouteBuilderExtensions.cs rename to RuntimeApps.Authentication/Endpoints/PasswordRecovery/ForgotPasswordApiEndpointRouteBuilderExtensions.cs index 19dfae0..d155cc8 100644 --- a/RuntimeApps.Authentication/Controller/ForgotPasswordApiEndpointRouteBuilderExtensions.cs +++ b/RuntimeApps.Authentication/Endpoints/PasswordRecovery/ForgotPasswordApiEndpointRouteBuilderExtensions.cs @@ -4,11 +4,12 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Routing; using Microsoft.Extensions.DependencyInjection; -using RuntimeApps.Authentication.Extensions; -using RuntimeApps.Authentication.Interface; -using RuntimeApps.Authentication.Model; - -namespace RuntimeApps.Authentication.Controller { +using RuntimeApps.Authentication.Features.PasswordRecovery.Contracts; +using RuntimeApps.Authentication.Features.PasswordRecovery.Models; +using RuntimeApps.Authentication.Features.Verification.Contracts; +using RuntimeApps.Authentication.Identity.Contracts; +using RuntimeApps.Authentication.Shared.Extensions; +namespace RuntimeApps.Authentication.Endpoints.PasswordRecovery { public static class ForgotPasswordApiEndpointRouteBuilderExtensions { /// /// Maps the optional password-recovery endpoints. Call this explicitly to expose them. @@ -40,27 +41,27 @@ public static IEndpointRouteBuilder MapForgotPasswordApi( [FromBody] ForgotPasswordRequestModel request, IForgotPasswordService service, HttpContext httpContext) => { - var result = await service.RequestAsync(request?.Email, httpContext.RequestAborted); - return TypedResults.Ok(result); - }).WithName("ForgotPassword"); + var result = await service.RequestAsync(request?.Email, httpContext.RequestAborted); + return TypedResults.Ok(result); + }).WithName("ForgotPassword"); group.MapPost("reset-password", async Task> ( [FromBody] ResetPasswordModel request, IForgotPasswordService service, HttpContext httpContext) => { - if(request == null) - return ValidationProblemFactory.CreateValidationProblem( - "InvalidPasswordReset", "The password reset request is invalid."); + if(request == null) + return ValidationProblemFactory.CreateValidationProblem( + "InvalidPasswordReset", "The password reset request is invalid."); - var result = await service.ResetAsync( - request.VerificationHandle, request.Credential, request.NewPassword, - httpContext.RequestAborted); - if(!result.Succeeded) - return result.CreateValidationProblem(); - return TypedResults.Ok(); - }).WithName("ResetPassword"); + var result = await service.ResetAsync( + request.VerificationHandle, request.Credential, request.NewPassword, + httpContext.RequestAborted); + if(!result.Succeeded) + return result.CreateValidationProblem(); + return TypedResults.Ok(); + }).WithName("ResetPassword"); return endpoints; } } -} \ No newline at end of file +} diff --git a/RuntimeApps.Authentication/Endpoints/RefreshTokens/RefreshTokenApiEndpointRouteBuilderExtensions.cs b/RuntimeApps.Authentication/Endpoints/RefreshTokens/RefreshTokenApiEndpointRouteBuilderExtensions.cs new file mode 100644 index 0000000..4f515e9 --- /dev/null +++ b/RuntimeApps.Authentication/Endpoints/RefreshTokens/RefreshTokenApiEndpointRouteBuilderExtensions.cs @@ -0,0 +1,198 @@ +using System.Net.Http.Json; +using Microsoft.AspNetCore.Authentication; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Identity; +using Microsoft.AspNetCore.Routing; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Options; +using RuntimeApps.Authentication.Features.RefreshTokens.Contracts; +using RuntimeApps.Authentication.Features.RefreshTokens.Models; +using RuntimeApps.Authentication.Features.RefreshTokens.Services; +using RuntimeApps.Authentication.Features.Verification.Models; +using RuntimeApps.Authentication.Identity.Contracts; +namespace RuntimeApps.Authentication.Endpoints.RefreshTokens { + public static class RefreshTokenApiEndpointRouteBuilderExtensions { + /// + /// Maps refresh, current-session logout, and logout-all endpoints. This is called automatically + /// by MapLoginApi when AddRefreshToken has registered the refresh-token service. + /// + public static IEndpointRouteBuilder MapRefreshTokenApi(this IEndpointRouteBuilder endpoints) + where TUser : IdentityUser + where TKey : IEquatable { + var routes = endpoints.MapGroup(""); + + routes.MapPost("refresh", async Task (HttpContext context, + IUserManager userManager, + ISignInManager signInManager, + IRefreshTokenService refreshTokenService, + IRefreshTokenRequestLimiter requestLimiter, + IServiceProvider services, + IAuthenticationSchemeProvider schemeProvider, + IAuthenticationHandlerProvider handlerProvider, + IOptions options, + IOptions verificationOptions) => { + if(!await requestLimiter.IsAllowedAsync(context, context.RequestAborted)) + return Results.StatusCode(StatusCodes.Status429TooManyRequests); + + var isCookie = await HasCookieSignInHandlerAsync(context, schemeProvider, handlerProvider); + RefreshTokenRequest request = null; + if(!isCookie && context.Request.HasJsonContentType()) + request = await context.Request.ReadFromJsonAsync(context.RequestAborted); + if(isCookie && !IsAllowedOrigin(context, options.Value)) + return Results.StatusCode(StatusCodes.Status403Forbidden); + + var suppliedToken = isCookie + ? context.Request.Cookies[options.Value.CookieName] + : request?.RefreshToken; + + var session = await refreshTokenService.RotateAsync(suppliedToken, context.RequestAborted); + if(session == null) + return Results.Unauthorized(); + + var user = await userManager.FindByIdAsync(Convert.ToString(session.UserId, System.Globalization.CultureInfo.InvariantCulture)); + if(user == null) { + await refreshTokenService.RevokeAsync(session.RefreshToken, context.RequestAborted); + return Results.Unauthorized(); + } + + var isLockedOut = await userManager.IsLockedOutAsync(user); + var hasExternalLogin = (await userManager.GetLoginsAsync(user)).Count > 0; + var emailPolicyAllowsSignIn = user.EmailConfirmed || + (hasExternalLogin && !verificationOptions.Value.RequireEmailVerificationForExternalLogins); + if(isLockedOut || !emailPolicyAllowsSignIn || + (user.EmailConfirmed && !await signInManager.CanSignInAsync(user))) { + await refreshTokenService.RevokeAsync(session.RefreshToken, context.RequestAborted); + return Results.Unauthorized(); + } + + try { + if(isCookie) { + await signInManager.SignInAsync(user, true); + AppendRefreshCookie(context, options.Value, session.RefreshToken, session.ExpiresAt); + return Results.NoContent(); + } + + var jwtProvider = services.GetService>(); + if(jwtProvider == null) { + await refreshTokenService.RevokeAsync(session.RefreshToken, CancellationToken.None); + return Results.Problem("JWT authentication is not configured.", statusCode: StatusCodes.Status500InternalServerError); + } + + var accessToken = await jwtProvider.GenerateTokenAsync(user); + accessToken.RefreshToken = session.RefreshToken; + accessToken.RefreshTokenExpireDate = session.ExpiresAt; + accessToken.SessionId = session.SessionId; + return Results.Ok(accessToken); + } catch { + await refreshTokenService.RevokeAsync(session.RefreshToken, CancellationToken.None); + throw; + } + }) + .Accepts(true, "application/json") + .WithSummary("Refresh the current session") + .WithDescription("JWT clients send a RefreshTokenRequest JSON body. Cookie clients send the refresh-token cookie; the JSON body is optional for cookie authentication."); + + routes.MapPost("logout", async Task (HttpContext context, + IRefreshTokenService refreshTokenService, + IOptions options) => { + var isCookie = await HasCookieSignInHandlerAsync(context, + context.RequestServices.GetRequiredService(), + context.RequestServices.GetRequiredService()); + RefreshTokenRequest request = null; + if(!isCookie && context.Request.HasJsonContentType()) + request = await context.Request.ReadFromJsonAsync(context.RequestAborted); + if(isCookie && !IsAllowedOrigin(context, options.Value)) + return Results.StatusCode(StatusCodes.Status403Forbidden); + + var token = isCookie + ? context.Request.Cookies[options.Value.CookieName] + : request?.RefreshToken; + await refreshTokenService.RevokeAsync(token, context.RequestAborted); + if(isCookie) + await context.SignOutAsync(); + context.Response.Cookies.Delete(options.Value.CookieName, new CookieOptions { + Path = options.Value.CookiePath, + Secure = options.Value.CookieSecure, + HttpOnly = true, + SameSite = options.Value.CookieSameSite + }); + return Results.NoContent(); + }) + .Accepts(true, "application/json") + .WithSummary("Log out the current session") + .WithDescription("JWT clients send a RefreshTokenRequest JSON body. Cookie clients send the refresh-token cookie; the JSON body is optional for cookie authentication."); + + routes.MapPost("logout/all", async Task (HttpContext context, + IUserManager userManager, + IRefreshTokenService refreshTokenService, + IOptions options) => { + var user = await userManager.GetUserAsync(context.User); + if(user == null) + return Results.Unauthorized(); + + var isCookie = await HasCookieSignInHandlerAsync(context, + context.RequestServices.GetRequiredService(), + context.RequestServices.GetRequiredService()); + if(isCookie && !IsAllowedOrigin(context, options.Value)) + return Results.StatusCode(StatusCodes.Status403Forbidden); + + await refreshTokenService.RevokeAllAsync(user.Id, context.RequestAborted); + if(isCookie) + await context.SignOutAsync(); + context.Response.Cookies.Delete(options.Value.CookieName, new CookieOptions { + Path = options.Value.CookiePath, + Secure = options.Value.CookieSecure, + HttpOnly = true, + SameSite = options.Value.CookieSameSite + }); + return Results.NoContent(); + }).RequireAuthorization(); + + return endpoints; + } + + private static async Task HasCookieSignInHandlerAsync( + HttpContext context, + IAuthenticationSchemeProvider schemeProvider, + IAuthenticationHandlerProvider handlerProvider) { + var scheme = await schemeProvider.GetDefaultSignInSchemeAsync(); + if(scheme == null) + return false; + + var handler = await handlerProvider.GetHandlerAsync(context, scheme.Name); + return handler is IAuthenticationSignInHandler; + } + + private static bool IsAllowedOrigin(HttpContext context, RefreshTokenOptions options) { + var origin = context.Request.Headers["Origin"].ToString(); + if(!Uri.TryCreate(origin, UriKind.Absolute, out var originUri) || + (originUri.Scheme != Uri.UriSchemeHttp && originUri.Scheme != Uri.UriSchemeHttps) || + originUri.AbsolutePath != "/" || !string.IsNullOrEmpty(originUri.Query) || + !string.IsNullOrEmpty(originUri.Fragment)) + return false; + + var normalizedOrigin = originUri.GetLeftPart(UriPartial.Authority).TrimEnd('/'); + var requestOrigin = $"{context.Request.Scheme}://{context.Request.Host}".TrimEnd('/'); + if(string.Equals(normalizedOrigin, requestOrigin, StringComparison.OrdinalIgnoreCase)) + return true; + + return options.AllowedOrigins?.Any(allowed => + string.Equals(allowed?.TrimEnd('/'), normalizedOrigin, StringComparison.OrdinalIgnoreCase)) == true; + } + + private static void AppendRefreshCookie( + HttpContext context, + RefreshTokenOptions options, + string refreshToken, + DateTimeOffset expiresAt) { + context.Response.Cookies.Append(options.CookieName, refreshToken, new CookieOptions { + HttpOnly = true, + Secure = options.CookieSecure, + SameSite = options.CookieSameSite, + Path = options.CookiePath, + Expires = expiresAt + }); + } + } +} diff --git a/RuntimeApps.Authentication/Controller/RoleApiEndpointRouteBuilderExtensions.cs b/RuntimeApps.Authentication/Endpoints/Roles/RoleApiEndpointRouteBuilderExtensions.cs similarity index 92% rename from RuntimeApps.Authentication/Controller/RoleApiEndpointRouteBuilderExtensions.cs rename to RuntimeApps.Authentication/Endpoints/Roles/RoleApiEndpointRouteBuilderExtensions.cs index 74aed67..b7ff7a9 100644 --- a/RuntimeApps.Authentication/Controller/RoleApiEndpointRouteBuilderExtensions.cs +++ b/RuntimeApps.Authentication/Endpoints/Roles/RoleApiEndpointRouteBuilderExtensions.cs @@ -1,12 +1,11 @@ -using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.HttpResults; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Routing; -using RuntimeApps.Authentication.Extensions; -using RuntimeApps.Authentication.Interface; - -namespace RuntimeApps.Authentication.Controller { +using RuntimeApps.Authentication.Identity.Contracts; +using RuntimeApps.Authentication.Shared.Extensions; +namespace RuntimeApps.Authentication.Endpoints.Roles { public static class RoleApiEndpointRouteBuilderExtensions { public static IEndpointRouteBuilder MapRoleGetApi(this IEndpointRouteBuilder endpoints) where TRole : class { diff --git a/RuntimeApps.Authentication/Controller/RoleClaimApiEndpointRouteBuilderExtensions.cs b/RuntimeApps.Authentication/Endpoints/Roles/RoleClaimApiEndpointRouteBuilderExtensions.cs similarity index 91% rename from RuntimeApps.Authentication/Controller/RoleClaimApiEndpointRouteBuilderExtensions.cs rename to RuntimeApps.Authentication/Endpoints/Roles/RoleClaimApiEndpointRouteBuilderExtensions.cs index c05be92..9fbb085 100644 --- a/RuntimeApps.Authentication/Controller/RoleClaimApiEndpointRouteBuilderExtensions.cs +++ b/RuntimeApps.Authentication/Endpoints/Roles/RoleClaimApiEndpointRouteBuilderExtensions.cs @@ -1,13 +1,12 @@ -using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.HttpResults; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Routing; -using RuntimeApps.Authentication.Extensions; -using RuntimeApps.Authentication.Interface; -using RuntimeApps.Authentication.Model; - -namespace RuntimeApps.Authentication.Controller { +using RuntimeApps.Authentication.Identity.Contracts; +using RuntimeApps.Authentication.Shared.Extensions; +using RuntimeApps.Authentication.Shared.Models; +namespace RuntimeApps.Authentication.Endpoints.Roles { public static class RoleClaimApiEndpointRouteBuilderExtensions { public static IEndpointRouteBuilder MapRoleClaimGetApi(this IEndpointRouteBuilder endpoints) where TRole : class { diff --git a/RuntimeApps.Authentication/Controller/UserApiEndpointRouteBuilderExtensions.cs b/RuntimeApps.Authentication/Endpoints/Users/UserApiEndpointRouteBuilderExtensions.cs similarity index 88% rename from RuntimeApps.Authentication/Controller/UserApiEndpointRouteBuilderExtensions.cs rename to RuntimeApps.Authentication/Endpoints/Users/UserApiEndpointRouteBuilderExtensions.cs index 603938f..1553aaf 100644 --- a/RuntimeApps.Authentication/Controller/UserApiEndpointRouteBuilderExtensions.cs +++ b/RuntimeApps.Authentication/Endpoints/Users/UserApiEndpointRouteBuilderExtensions.cs @@ -1,9 +1,8 @@ -using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Routing; -using RuntimeApps.Authentication.Interface; - -namespace RuntimeApps.Authentication.Controller { +using RuntimeApps.Authentication.Identity.Contracts; +namespace RuntimeApps.Authentication.Endpoints.Users { public static class UserApiEndpointRouteBuilderExtensions { public static IEndpointRouteBuilder MapUserGetApi(this IEndpointRouteBuilder endpoints) where TUser : class diff --git a/RuntimeApps.Authentication/Controller/UserClaimApiEndpointRouteBuilderExtensions.cs b/RuntimeApps.Authentication/Endpoints/Users/UserClaimApiEndpointRouteBuilderExtensions.cs similarity index 93% rename from RuntimeApps.Authentication/Controller/UserClaimApiEndpointRouteBuilderExtensions.cs rename to RuntimeApps.Authentication/Endpoints/Users/UserClaimApiEndpointRouteBuilderExtensions.cs index e4615af..66ee0f9 100644 --- a/RuntimeApps.Authentication/Controller/UserClaimApiEndpointRouteBuilderExtensions.cs +++ b/RuntimeApps.Authentication/Endpoints/Users/UserClaimApiEndpointRouteBuilderExtensions.cs @@ -1,13 +1,12 @@ -using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.HttpResults; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Routing; -using RuntimeApps.Authentication.Extensions; -using RuntimeApps.Authentication.Interface; -using RuntimeApps.Authentication.Model; - -namespace RuntimeApps.Authentication.Controller { +using RuntimeApps.Authentication.Identity.Contracts; +using RuntimeApps.Authentication.Shared.Extensions; +using RuntimeApps.Authentication.Shared.Models; +namespace RuntimeApps.Authentication.Endpoints.Users { public static class UserClaimApiEndpointRouteBuilderExtensions { public static IEndpointRouteBuilder MapUserClaimGetApi(this IEndpointRouteBuilder endpoints) where TUser : class { diff --git a/RuntimeApps.Authentication/Controller/UserRoleApiEndpointRouteBuilderExtensions.cs b/RuntimeApps.Authentication/Endpoints/Users/UserRoleApiEndpointRouteBuilderExtensions.cs similarity index 94% rename from RuntimeApps.Authentication/Controller/UserRoleApiEndpointRouteBuilderExtensions.cs rename to RuntimeApps.Authentication/Endpoints/Users/UserRoleApiEndpointRouteBuilderExtensions.cs index c8990cb..f83dc3e 100644 --- a/RuntimeApps.Authentication/Controller/UserRoleApiEndpointRouteBuilderExtensions.cs +++ b/RuntimeApps.Authentication/Endpoints/Users/UserRoleApiEndpointRouteBuilderExtensions.cs @@ -1,12 +1,11 @@ -using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.HttpResults; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Routing; -using RuntimeApps.Authentication.Extensions; -using RuntimeApps.Authentication.Interface; - -namespace RuntimeApps.Authentication.Controller { +using RuntimeApps.Authentication.Identity.Contracts; +using RuntimeApps.Authentication.Shared.Extensions; +namespace RuntimeApps.Authentication.Endpoints.Users { public static class UserRoleApiEndpointRouteBuilderExtensions { public static IEndpointRouteBuilder MapUserRoleGetApi(this IEndpointRouteBuilder endpoints) where TUser : class { diff --git a/RuntimeApps.Authentication/Interface/IUserAccountService.cs b/RuntimeApps.Authentication/Features/Account/Contracts/IUserAccountService.cs similarity index 71% rename from RuntimeApps.Authentication/Interface/IUserAccountService.cs rename to RuntimeApps.Authentication/Features/Account/Contracts/IUserAccountService.cs index 61d25c4..b1ac03a 100644 --- a/RuntimeApps.Authentication/Interface/IUserAccountService.cs +++ b/RuntimeApps.Authentication/Features/Account/Contracts/IUserAccountService.cs @@ -1,9 +1,8 @@ -using RuntimeApps.Authentication.Model; - -namespace RuntimeApps.Authentication.Interface { +using RuntimeApps.Authentication.Shared.Models; +namespace RuntimeApps.Authentication.Features.Account.Contracts { public interface IUserAccountService { Task> CompleteRegistrationAsync(TUser user); Task> LoginAsync(string userName, string password); Task> ExternalLoginAsync(string provider, string token); } -} \ No newline at end of file +} diff --git a/RuntimeApps.Authentication/Model/ChangePasswordModel.cs b/RuntimeApps.Authentication/Features/Account/Models/ChangePasswordModel.cs similarity index 70% rename from RuntimeApps.Authentication/Model/ChangePasswordModel.cs rename to RuntimeApps.Authentication/Features/Account/Models/ChangePasswordModel.cs index c3bed66..617b8e3 100644 --- a/RuntimeApps.Authentication/Model/ChangePasswordModel.cs +++ b/RuntimeApps.Authentication/Features/Account/Models/ChangePasswordModel.cs @@ -1,4 +1,4 @@ -namespace RuntimeApps.Authentication.Model { +namespace RuntimeApps.Authentication.Features.Account.Models { public class ChangePasswordModel { public string CurrentPassword { get; set; } public string NewPassword { get; set; } diff --git a/RuntimeApps.Authentication/Model/UserLoginModel.cs b/RuntimeApps.Authentication/Features/Account/Models/UserLoginModel.cs similarity index 67% rename from RuntimeApps.Authentication/Model/UserLoginModel.cs rename to RuntimeApps.Authentication/Features/Account/Models/UserLoginModel.cs index 46b11b8..9320a76 100644 --- a/RuntimeApps.Authentication/Model/UserLoginModel.cs +++ b/RuntimeApps.Authentication/Features/Account/Models/UserLoginModel.cs @@ -1,4 +1,4 @@ -namespace RuntimeApps.Authentication.Model { +namespace RuntimeApps.Authentication.Features.Account.Models { public class UserLoginModel { public string UserName { get; set; } public string Password { get; set; } diff --git a/RuntimeApps.Authentication/Model/UserRegisterModel.cs b/RuntimeApps.Authentication/Features/Account/Models/UserRegisterModel.cs similarity index 69% rename from RuntimeApps.Authentication/Model/UserRegisterModel.cs rename to RuntimeApps.Authentication/Features/Account/Models/UserRegisterModel.cs index 34b8f98..dbb3bd1 100644 --- a/RuntimeApps.Authentication/Model/UserRegisterModel.cs +++ b/RuntimeApps.Authentication/Features/Account/Models/UserRegisterModel.cs @@ -1,6 +1,6 @@ -using Microsoft.AspNetCore.Identity; +using Microsoft.AspNetCore.Identity; -namespace RuntimeApps.Authentication.Model { +namespace RuntimeApps.Authentication.Features.Account.Models { public class UserRegisterModel where TUser : IdentityUser where TKey : IEquatable { diff --git a/RuntimeApps.Authentication/Service/JwtProvider.cs b/RuntimeApps.Authentication/Features/Account/Services/JwtProvider.cs similarity index 88% rename from RuntimeApps.Authentication/Service/JwtProvider.cs rename to RuntimeApps.Authentication/Features/Account/Services/JwtProvider.cs index ea2e89b..b6126a8 100644 --- a/RuntimeApps.Authentication/Service/JwtProvider.cs +++ b/RuntimeApps.Authentication/Features/Account/Services/JwtProvider.cs @@ -1,12 +1,11 @@ -using System.IdentityModel.Tokens.Jwt; +using System.IdentityModel.Tokens.Jwt; using Microsoft.AspNetCore.Authentication.JwtBearer; using Microsoft.AspNetCore.Identity; using Microsoft.Extensions.Options; using Microsoft.IdentityModel.Tokens; -using RuntimeApps.Authentication.Interface; -using RuntimeApps.Authentication.Model; - -namespace RuntimeApps.Authentication.Service { +using RuntimeApps.Authentication.Identity.Contracts; +using RuntimeApps.Authentication.Shared.Models; +namespace RuntimeApps.Authentication.Features.Account.Services { public class JwtProvider: IJwtProvider where TUser : IdentityUser where TKey : IEquatable { diff --git a/RuntimeApps.Authentication/Service/UserAccountService.cs b/RuntimeApps.Authentication/Features/Account/Services/UserAccountService.cs similarity index 96% rename from RuntimeApps.Authentication/Service/UserAccountService.cs rename to RuntimeApps.Authentication/Features/Account/Services/UserAccountService.cs index 1ff4fff..f48d01a 100644 --- a/RuntimeApps.Authentication/Service/UserAccountService.cs +++ b/RuntimeApps.Authentication/Features/Account/Services/UserAccountService.cs @@ -2,10 +2,15 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Identity; using Microsoft.Extensions.Options; -using RuntimeApps.Authentication.Interface; -using RuntimeApps.Authentication.Model; - -namespace RuntimeApps.Authentication.Service { +using RuntimeApps.Authentication.Features.Account.Contracts; +using RuntimeApps.Authentication.Features.ExternalLogin.Contracts; +using RuntimeApps.Authentication.Features.RefreshTokens.Contracts; +using RuntimeApps.Authentication.Features.Verification.Contracts; +using RuntimeApps.Authentication.Identity.Contracts; +using RuntimeApps.Authentication.Features.RefreshTokens.Models; +using RuntimeApps.Authentication.Features.Verification.Models; +using RuntimeApps.Authentication.Shared.Models; +namespace RuntimeApps.Authentication.Features.Account.Services { public class UserAccountService: IUserAccountService where TUser : IdentityUser where TKey : IEquatable { @@ -243,4 +248,4 @@ private async Task HasHandlerAsync() { return handler is IAuthenticationSignInHandler; } } -} \ No newline at end of file +} diff --git a/RuntimeApps.Authentication/Interface/IExternalLoginEmailTrustPolicy.cs b/RuntimeApps.Authentication/Features/ExternalLogin/Contracts/IExternalLoginEmailTrustPolicy.cs similarity index 56% rename from RuntimeApps.Authentication/Interface/IExternalLoginEmailTrustPolicy.cs rename to RuntimeApps.Authentication/Features/ExternalLogin/Contracts/IExternalLoginEmailTrustPolicy.cs index 87b98e6..e1dc08a 100644 --- a/RuntimeApps.Authentication/Interface/IExternalLoginEmailTrustPolicy.cs +++ b/RuntimeApps.Authentication/Features/ExternalLogin/Contracts/IExternalLoginEmailTrustPolicy.cs @@ -1,7 +1,6 @@ -using RuntimeApps.Authentication.Model; - -namespace RuntimeApps.Authentication.Interface { +using RuntimeApps.Authentication.Features.ExternalLogin.Models; +namespace RuntimeApps.Authentication.Features.ExternalLogin.Contracts { public interface IExternalLoginEmailTrustPolicy where TUser : class { bool IsEmailTrusted(string provider, ExternalLoginProviderResult result); } -} \ No newline at end of file +} diff --git a/RuntimeApps.Authentication/Interface/IExternalLoginProvider.cs b/RuntimeApps.Authentication/Features/ExternalLogin/Contracts/IExternalLoginProvider.cs similarity index 57% rename from RuntimeApps.Authentication/Interface/IExternalLoginProvider.cs rename to RuntimeApps.Authentication/Features/ExternalLogin/Contracts/IExternalLoginProvider.cs index 883f4ce..cf75d97 100644 --- a/RuntimeApps.Authentication/Interface/IExternalLoginProvider.cs +++ b/RuntimeApps.Authentication/Features/ExternalLogin/Contracts/IExternalLoginProvider.cs @@ -1,8 +1,7 @@ -using RuntimeApps.Authentication.Model; - -namespace RuntimeApps.Authentication.Interface { +using RuntimeApps.Authentication.Features.ExternalLogin.Models; +namespace RuntimeApps.Authentication.Features.ExternalLogin.Contracts { public interface IExternalLoginProvider where TUser : class { string Provider { get; } Task> ValidateAsync(string token); } -} \ No newline at end of file +} diff --git a/RuntimeApps.Authentication/Model/BaseExternalLoginOption.cs b/RuntimeApps.Authentication/Features/ExternalLogin/Models/BaseExternalLoginOption.cs similarity index 67% rename from RuntimeApps.Authentication/Model/BaseExternalLoginOption.cs rename to RuntimeApps.Authentication/Features/ExternalLogin/Models/BaseExternalLoginOption.cs index 4799180..839f7b7 100644 --- a/RuntimeApps.Authentication/Model/BaseExternalLoginOption.cs +++ b/RuntimeApps.Authentication/Features/ExternalLogin/Models/BaseExternalLoginOption.cs @@ -1,4 +1,4 @@ -namespace RuntimeApps.Authentication.Model { +namespace RuntimeApps.Authentication.Features.ExternalLogin.Models { public class BaseExternalLoginOption { public string ClientId { get; set; } public string ClientSecret { get; set; } diff --git a/RuntimeApps.Authentication/Model/ExternalAuthModel.cs b/RuntimeApps.Authentication/Features/ExternalLogin/Models/ExternalAuthModel.cs similarity index 65% rename from RuntimeApps.Authentication/Model/ExternalAuthModel.cs rename to RuntimeApps.Authentication/Features/ExternalLogin/Models/ExternalAuthModel.cs index 9520365..303d04f 100644 --- a/RuntimeApps.Authentication/Model/ExternalAuthModel.cs +++ b/RuntimeApps.Authentication/Features/ExternalLogin/Models/ExternalAuthModel.cs @@ -1,4 +1,4 @@ -namespace RuntimeApps.Authentication.Model { +namespace RuntimeApps.Authentication.Features.ExternalLogin.Models { public class ExternalAuthModel { public string Provider { get; set; } public string Token { get; set; } diff --git a/RuntimeApps.Authentication/Model/ExternalLoginProviderResult.cs b/RuntimeApps.Authentication/Features/ExternalLogin/Models/ExternalLoginProviderResult.cs similarity index 83% rename from RuntimeApps.Authentication/Model/ExternalLoginProviderResult.cs rename to RuntimeApps.Authentication/Features/ExternalLogin/Models/ExternalLoginProviderResult.cs index 2e38384..3c05871 100644 --- a/RuntimeApps.Authentication/Model/ExternalLoginProviderResult.cs +++ b/RuntimeApps.Authentication/Features/ExternalLogin/Models/ExternalLoginProviderResult.cs @@ -1,6 +1,6 @@ using Microsoft.AspNetCore.Identity; -namespace RuntimeApps.Authentication.Model { +namespace RuntimeApps.Authentication.Features.ExternalLogin.Models { public sealed class ExternalLoginProviderResult where TUser : class { public TUser User { get; init; } public UserLoginInfo LoginInfo { get; init; } @@ -8,4 +8,4 @@ public sealed class ExternalLoginProviderResult where TUser : class { public bool EmailVerified { get; init; } public string HostedDomain { get; init; } } -} \ No newline at end of file +} diff --git a/RuntimeApps.Authentication/Model/Facebook/FacebookAppAccessToken.cs b/RuntimeApps.Authentication/Features/ExternalLogin/Models/Facebook/FacebookAppAccessToken.cs similarity index 65% rename from RuntimeApps.Authentication/Model/Facebook/FacebookAppAccessToken.cs rename to RuntimeApps.Authentication/Features/ExternalLogin/Models/Facebook/FacebookAppAccessToken.cs index 8b9fae4..875d2bf 100644 --- a/RuntimeApps.Authentication/Model/Facebook/FacebookAppAccessToken.cs +++ b/RuntimeApps.Authentication/Features/ExternalLogin/Models/Facebook/FacebookAppAccessToken.cs @@ -1,4 +1,4 @@ -namespace RuntimeApps.Authentication.Model.Facebook { +namespace RuntimeApps.Authentication.Features.ExternalLogin.Models.Facebook { internal class FacebookAppAccessToken { public string? Token_type { get; set; } public string? Access_token { get; set; } diff --git a/RuntimeApps.Authentication/Model/Facebook/FacebookPicture.cs b/RuntimeApps.Authentication/Features/ExternalLogin/Models/Facebook/FacebookPicture.cs similarity index 67% rename from RuntimeApps.Authentication/Model/Facebook/FacebookPicture.cs rename to RuntimeApps.Authentication/Features/ExternalLogin/Models/Facebook/FacebookPicture.cs index 77a7d7e..3fd64b4 100644 --- a/RuntimeApps.Authentication/Model/Facebook/FacebookPicture.cs +++ b/RuntimeApps.Authentication/Features/ExternalLogin/Models/Facebook/FacebookPicture.cs @@ -1,4 +1,4 @@ -namespace RuntimeApps.Authentication.Model.Facebook { +namespace RuntimeApps.Authentication.Features.ExternalLogin.Models.Facebook { public class FacebookPicture { public int? Height { get; set; } public int? Width { get; set; } diff --git a/RuntimeApps.Authentication/Model/Facebook/FacebookPictureData.cs b/RuntimeApps.Authentication/Features/ExternalLogin/Models/Facebook/FacebookPictureData.cs similarity index 55% rename from RuntimeApps.Authentication/Model/Facebook/FacebookPictureData.cs rename to RuntimeApps.Authentication/Features/ExternalLogin/Models/Facebook/FacebookPictureData.cs index e2aa611..adce7c7 100644 --- a/RuntimeApps.Authentication/Model/Facebook/FacebookPictureData.cs +++ b/RuntimeApps.Authentication/Features/ExternalLogin/Models/Facebook/FacebookPictureData.cs @@ -1,4 +1,4 @@ -namespace RuntimeApps.Authentication.Model.Facebook { +namespace RuntimeApps.Authentication.Features.ExternalLogin.Models.Facebook { public class FacebookPictureData { public FacebookPicture? Data { get; set; } } diff --git a/RuntimeApps.Authentication/Model/Facebook/FacebookUserAccessTokenData.cs b/RuntimeApps.Authentication/Features/ExternalLogin/Models/Facebook/FacebookUserAccessTokenData.cs similarity index 80% rename from RuntimeApps.Authentication/Model/Facebook/FacebookUserAccessTokenData.cs rename to RuntimeApps.Authentication/Features/ExternalLogin/Models/Facebook/FacebookUserAccessTokenData.cs index 49bdc1e..a83f3da 100644 --- a/RuntimeApps.Authentication/Model/Facebook/FacebookUserAccessTokenData.cs +++ b/RuntimeApps.Authentication/Features/ExternalLogin/Models/Facebook/FacebookUserAccessTokenData.cs @@ -1,4 +1,4 @@ -namespace RuntimeApps.Authentication.Model.Facebook { +namespace RuntimeApps.Authentication.Features.ExternalLogin.Models.Facebook { internal class FacebookUserAccessTokenData { public long? App_id { get; set; } public string Type { get; set; } diff --git a/RuntimeApps.Authentication/Model/Facebook/FacebookUserAccessTokenValidation.cs b/RuntimeApps.Authentication/Features/ExternalLogin/Models/Facebook/FacebookUserAccessTokenValidation.cs similarity index 61% rename from RuntimeApps.Authentication/Model/Facebook/FacebookUserAccessTokenValidation.cs rename to RuntimeApps.Authentication/Features/ExternalLogin/Models/Facebook/FacebookUserAccessTokenValidation.cs index cd05fc9..cdaa624 100644 --- a/RuntimeApps.Authentication/Model/Facebook/FacebookUserAccessTokenValidation.cs +++ b/RuntimeApps.Authentication/Features/ExternalLogin/Models/Facebook/FacebookUserAccessTokenValidation.cs @@ -1,4 +1,4 @@ -namespace RuntimeApps.Authentication.Model.Facebook { +namespace RuntimeApps.Authentication.Features.ExternalLogin.Models.Facebook { internal class FacebookUserAccessTokenValidation { public FacebookUserAccessTokenData? Data { get; set; } } diff --git a/RuntimeApps.Authentication/Model/Facebook/FacebookUserData.cs b/RuntimeApps.Authentication/Features/ExternalLogin/Models/Facebook/FacebookUserData.cs similarity index 83% rename from RuntimeApps.Authentication/Model/Facebook/FacebookUserData.cs rename to RuntimeApps.Authentication/Features/ExternalLogin/Models/Facebook/FacebookUserData.cs index 17e46b1..0e7d33d 100644 --- a/RuntimeApps.Authentication/Model/Facebook/FacebookUserData.cs +++ b/RuntimeApps.Authentication/Features/ExternalLogin/Models/Facebook/FacebookUserData.cs @@ -1,4 +1,4 @@ -namespace RuntimeApps.Authentication.Model.Facebook { +namespace RuntimeApps.Authentication.Features.ExternalLogin.Models.Facebook { public class FacebookUserData { public long? Id { get; set; } public string? Email { get; set; } diff --git a/RuntimeApps.Authentication/Model/FacebookExternalLoginOption.cs b/RuntimeApps.Authentication/Features/ExternalLogin/Models/FacebookExternalLoginOption.cs similarity index 83% rename from RuntimeApps.Authentication/Model/FacebookExternalLoginOption.cs rename to RuntimeApps.Authentication/Features/ExternalLogin/Models/FacebookExternalLoginOption.cs index a210095..56fcd6a 100644 --- a/RuntimeApps.Authentication/Model/FacebookExternalLoginOption.cs +++ b/RuntimeApps.Authentication/Features/ExternalLogin/Models/FacebookExternalLoginOption.cs @@ -1,7 +1,8 @@ +using RuntimeApps.Authentication.Shared.Models; using Microsoft.AspNetCore.Identity; -using RuntimeApps.Authentication.Model.Facebook; +using RuntimeApps.Authentication.Features.ExternalLogin.Models.Facebook; -namespace RuntimeApps.Authentication.Model { +namespace RuntimeApps.Authentication.Features.ExternalLogin.Models { public class FacebookExternalLoginOption : BaseExternalLoginOption where TUser : class, new() { public string AccessTokenUrl { get; set; } = "https://graph.facebook.com/oauth/access_token?client_id={0}&client_secret={1}&grant_type=client_credentials"; @@ -18,4 +19,4 @@ public static TIdentityUser UserIdentityMapper(FacebookUser }; } } -} \ No newline at end of file +} diff --git a/RuntimeApps.Authentication/Model/GoogleExternalLoginOption.cs b/RuntimeApps.Authentication/Features/ExternalLogin/Models/GoogleExternalLoginOption.cs similarity index 81% rename from RuntimeApps.Authentication/Model/GoogleExternalLoginOption.cs rename to RuntimeApps.Authentication/Features/ExternalLogin/Models/GoogleExternalLoginOption.cs index ccddbc0..cbe5455 100644 --- a/RuntimeApps.Authentication/Model/GoogleExternalLoginOption.cs +++ b/RuntimeApps.Authentication/Features/ExternalLogin/Models/GoogleExternalLoginOption.cs @@ -1,7 +1,8 @@ -using Google.Apis.Auth; +using RuntimeApps.Authentication.Shared.Models; +using Google.Apis.Auth; using Microsoft.AspNetCore.Identity; -namespace RuntimeApps.Authentication.Model { +namespace RuntimeApps.Authentication.Features.ExternalLogin.Models { public class GoogleExternalLoginOption: BaseExternalLoginOption where TUser : class, new() { public Func Mapper { get; set; } = (data) => new TUser(); diff --git a/RuntimeApps.Authentication/Model/MicrosoftExternalLoginOption.cs b/RuntimeApps.Authentication/Features/ExternalLogin/Models/MicrosoftExternalLoginOption.cs similarity index 85% rename from RuntimeApps.Authentication/Model/MicrosoftExternalLoginOption.cs rename to RuntimeApps.Authentication/Features/ExternalLogin/Models/MicrosoftExternalLoginOption.cs index 06582d5..8f65fb4 100644 --- a/RuntimeApps.Authentication/Model/MicrosoftExternalLoginOption.cs +++ b/RuntimeApps.Authentication/Features/ExternalLogin/Models/MicrosoftExternalLoginOption.cs @@ -1,7 +1,8 @@ -using System.IdentityModel.Tokens.Jwt; +using RuntimeApps.Authentication.Shared.Models; +using System.IdentityModel.Tokens.Jwt; using Microsoft.AspNetCore.Identity; -namespace RuntimeApps.Authentication.Model { +namespace RuntimeApps.Authentication.Features.ExternalLogin.Models { public class MicrosoftExternalLoginOption: BaseExternalLoginOption where TUser : class, new() { public string IssuerEndpoint { get; set; } = "https://login.microsoftonline.com/common/v2.0/"; diff --git a/RuntimeApps.Authentication/Service/ExternalLoginProviders/FacebookExternalLoginProvider.cs b/RuntimeApps.Authentication/Features/ExternalLogin/Providers/FacebookExternalLoginProvider.cs similarity index 93% rename from RuntimeApps.Authentication/Service/ExternalLoginProviders/FacebookExternalLoginProvider.cs rename to RuntimeApps.Authentication/Features/ExternalLogin/Providers/FacebookExternalLoginProvider.cs index e70efd8..ea62bde 100644 --- a/RuntimeApps.Authentication/Service/ExternalLoginProviders/FacebookExternalLoginProvider.cs +++ b/RuntimeApps.Authentication/Features/ExternalLogin/Providers/FacebookExternalLoginProvider.cs @@ -4,11 +4,12 @@ using Microsoft.Extensions.Options; using Microsoft.Extensions.Logging; using Newtonsoft.Json; -using RuntimeApps.Authentication.Interface; -using RuntimeApps.Authentication.Model; -using RuntimeApps.Authentication.Model.Facebook; +using RuntimeApps.Authentication.Features.ExternalLogin.Contracts; +using RuntimeApps.Authentication.Identity.Contracts; +using RuntimeApps.Authentication.Features.ExternalLogin.Models; +using RuntimeApps.Authentication.Features.ExternalLogin.Models.Facebook; -namespace RuntimeApps.Authentication.Service.ExternalLoginProviders { +namespace RuntimeApps.Authentication.Features.ExternalLogin.Providers { public class FacebookExternalLoginProvider : IExternalLoginProvider where TUser : class, new() { private readonly IOptions> _options; @@ -92,4 +93,4 @@ public async Task> ValidateAsync(string token } } } -} \ No newline at end of file +} diff --git a/RuntimeApps.Authentication/Service/ExternalLoginProviders/GoogleExternalLoginProvider.cs b/RuntimeApps.Authentication/Features/ExternalLogin/Providers/GoogleExternalLoginProvider.cs similarity index 88% rename from RuntimeApps.Authentication/Service/ExternalLoginProviders/GoogleExternalLoginProvider.cs rename to RuntimeApps.Authentication/Features/ExternalLogin/Providers/GoogleExternalLoginProvider.cs index c7ae4b6..801e252 100644 --- a/RuntimeApps.Authentication/Service/ExternalLoginProviders/GoogleExternalLoginProvider.cs +++ b/RuntimeApps.Authentication/Features/ExternalLogin/Providers/GoogleExternalLoginProvider.cs @@ -1,12 +1,11 @@ using Google.Apis.Auth; using Microsoft.AspNetCore.Identity; -using Microsoft.Extensions.Options; using Microsoft.Extensions.Logging; -using RuntimeApps.Authentication.Interface; -using RuntimeApps.Authentication.Model; - -namespace RuntimeApps.Authentication.Service.ExternalLoginProviders { - public class GoogleExternalLoginProvider : IExternalLoginProvider +using Microsoft.Extensions.Options; +using RuntimeApps.Authentication.Features.ExternalLogin.Contracts; +using RuntimeApps.Authentication.Features.ExternalLogin.Models; +namespace RuntimeApps.Authentication.Features.ExternalLogin.Providers { + public class GoogleExternalLoginProvider: IExternalLoginProvider where TUser : class, new() { private readonly IOptions> _options; private readonly ILogger> _logger; @@ -55,4 +54,4 @@ public async Task> ValidateAsync(string token } } } -} \ No newline at end of file +} diff --git a/RuntimeApps.Authentication/Service/ExternalLoginProviders/MicrosoftExternalLoginProvider.cs b/RuntimeApps.Authentication/Features/ExternalLogin/Providers/MicrosoftExternalLoginProvider.cs similarity index 95% rename from RuntimeApps.Authentication/Service/ExternalLoginProviders/MicrosoftExternalLoginProvider.cs rename to RuntimeApps.Authentication/Features/ExternalLogin/Providers/MicrosoftExternalLoginProvider.cs index d47b73a..f0ba232 100644 --- a/RuntimeApps.Authentication/Service/ExternalLoginProviders/MicrosoftExternalLoginProvider.cs +++ b/RuntimeApps.Authentication/Features/ExternalLogin/Providers/MicrosoftExternalLoginProvider.cs @@ -1,15 +1,14 @@ using System.IdentityModel.Tokens.Jwt; using Microsoft.AspNetCore.Identity; -using Microsoft.Extensions.Options; using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Options; using Microsoft.IdentityModel.Protocols; using Microsoft.IdentityModel.Protocols.OpenIdConnect; using Microsoft.IdentityModel.Tokens; -using RuntimeApps.Authentication.Interface; -using RuntimeApps.Authentication.Model; - -namespace RuntimeApps.Authentication.Service.ExternalLoginProviders { - public class MicrosoftExternalLoginProvider : IExternalLoginProvider +using RuntimeApps.Authentication.Features.ExternalLogin.Contracts; +using RuntimeApps.Authentication.Features.ExternalLogin.Models; +namespace RuntimeApps.Authentication.Features.ExternalLogin.Providers { + public class MicrosoftExternalLoginProvider: IExternalLoginProvider where TUser : class, new() { private readonly IOptions> _options; private readonly IHttpClientFactory _httpClientFactory; @@ -106,4 +105,4 @@ public async Task> ValidateAsync(string token } } } -} \ No newline at end of file +} diff --git a/RuntimeApps.Authentication/Service/DefaultExternalLoginEmailTrustPolicy.cs b/RuntimeApps.Authentication/Features/ExternalLogin/Services/DefaultExternalLoginEmailTrustPolicy.cs similarity index 83% rename from RuntimeApps.Authentication/Service/DefaultExternalLoginEmailTrustPolicy.cs rename to RuntimeApps.Authentication/Features/ExternalLogin/Services/DefaultExternalLoginEmailTrustPolicy.cs index 29110ae..3db5092 100644 --- a/RuntimeApps.Authentication/Service/DefaultExternalLoginEmailTrustPolicy.cs +++ b/RuntimeApps.Authentication/Features/ExternalLogin/Services/DefaultExternalLoginEmailTrustPolicy.cs @@ -1,12 +1,11 @@ -using RuntimeApps.Authentication.Interface; -using RuntimeApps.Authentication.Model; - -namespace RuntimeApps.Authentication.Service { +using RuntimeApps.Authentication.Features.ExternalLogin.Contracts; +using RuntimeApps.Authentication.Features.ExternalLogin.Models; +namespace RuntimeApps.Authentication.Features.ExternalLogin.Services { /// /// Trusts verified Google Gmail/Googlemail addresses and verified Google Workspace addresses /// whose email domain matches the token's hosted-domain claim. Other providers require a custom policy. /// - public sealed class DefaultExternalLoginEmailTrustPolicy : IExternalLoginEmailTrustPolicy + public sealed class DefaultExternalLoginEmailTrustPolicy: IExternalLoginEmailTrustPolicy where TUser : class { public bool IsEmailTrusted(string provider, ExternalLoginProviderResult result) { if(result == null || !result.EmailVerified || string.IsNullOrWhiteSpace(result.Email) || @@ -26,4 +25,4 @@ public bool IsEmailTrusted(string provider, ExternalLoginProviderResult r emailDomain.Equals(result.HostedDomain, StringComparison.OrdinalIgnoreCase); } } -} \ No newline at end of file +} diff --git a/RuntimeApps.Authentication/Interface/IForgotPasswordService.cs b/RuntimeApps.Authentication/Features/PasswordRecovery/Contracts/IForgotPasswordService.cs similarity index 64% rename from RuntimeApps.Authentication/Interface/IForgotPasswordService.cs rename to RuntimeApps.Authentication/Features/PasswordRecovery/Contracts/IForgotPasswordService.cs index 92c34cc..ceb5c6e 100644 --- a/RuntimeApps.Authentication/Interface/IForgotPasswordService.cs +++ b/RuntimeApps.Authentication/Features/PasswordRecovery/Contracts/IForgotPasswordService.cs @@ -1,8 +1,8 @@ -using RuntimeApps.Authentication.Model; - -namespace RuntimeApps.Authentication.Interface { +using RuntimeApps.Authentication.Features.PasswordRecovery.Models; +using RuntimeApps.Authentication.Shared.Models; +namespace RuntimeApps.Authentication.Features.PasswordRecovery.Contracts { public interface IForgotPasswordService where TKey : IEquatable { Task RequestAsync(string email, CancellationToken cancellationToken = default); Task ResetAsync(string verificationHandle, string credential, string newPassword, CancellationToken cancellationToken = default); } -} \ No newline at end of file +} diff --git a/RuntimeApps.Authentication/Interface/IForgotPasswordVerificationWorkflow.cs b/RuntimeApps.Authentication/Features/PasswordRecovery/Contracts/IForgotPasswordVerificationWorkflow.cs similarity index 72% rename from RuntimeApps.Authentication/Interface/IForgotPasswordVerificationWorkflow.cs rename to RuntimeApps.Authentication/Features/PasswordRecovery/Contracts/IForgotPasswordVerificationWorkflow.cs index e461779..badf809 100644 --- a/RuntimeApps.Authentication/Interface/IForgotPasswordVerificationWorkflow.cs +++ b/RuntimeApps.Authentication/Features/PasswordRecovery/Contracts/IForgotPasswordVerificationWorkflow.cs @@ -1,6 +1,7 @@ -using RuntimeApps.Authentication.Model; - -namespace RuntimeApps.Authentication.Interface { +using RuntimeApps.Authentication.Features.Verification.Contracts; +using RuntimeApps.Authentication.Features.Verification.Models; +using RuntimeApps.Authentication.Shared.Models; +namespace RuntimeApps.Authentication.Features.PasswordRecovery.Contracts { /// /// Additional verification capability used by password recovery. Kept separate to avoid /// expanding the existing public verification interface. @@ -12,4 +13,4 @@ Task> CheckAsync(string verificationHandle, string credential, VerificationPurpose expectedPurpose, VerificationChannel expectedChannel, CancellationToken cancellationToken = default); } -} \ No newline at end of file +} diff --git a/RuntimeApps.Authentication/Model/ForgotPasswordMethod.cs b/RuntimeApps.Authentication/Features/PasswordRecovery/Models/ForgotPasswordMethod.cs similarity index 66% rename from RuntimeApps.Authentication/Model/ForgotPasswordMethod.cs rename to RuntimeApps.Authentication/Features/PasswordRecovery/Models/ForgotPasswordMethod.cs index 3ed79fd..6523943 100644 --- a/RuntimeApps.Authentication/Model/ForgotPasswordMethod.cs +++ b/RuntimeApps.Authentication/Features/PasswordRecovery/Models/ForgotPasswordMethod.cs @@ -1,4 +1,4 @@ -namespace RuntimeApps.Authentication.Model { +namespace RuntimeApps.Authentication.Features.PasswordRecovery.Models { /// Determines how a password-reset credential is delivered. public enum ForgotPasswordMethod { VerificationCode, Link } -} \ No newline at end of file +} diff --git a/RuntimeApps.Authentication/Model/ForgotPasswordOptions.cs b/RuntimeApps.Authentication/Features/PasswordRecovery/Models/ForgotPasswordOptions.cs similarity index 93% rename from RuntimeApps.Authentication/Model/ForgotPasswordOptions.cs rename to RuntimeApps.Authentication/Features/PasswordRecovery/Models/ForgotPasswordOptions.cs index c515610..3285ce3 100644 --- a/RuntimeApps.Authentication/Model/ForgotPasswordOptions.cs +++ b/RuntimeApps.Authentication/Features/PasswordRecovery/Models/ForgotPasswordOptions.cs @@ -1,4 +1,4 @@ -namespace RuntimeApps.Authentication.Model { +namespace RuntimeApps.Authentication.Features.PasswordRecovery.Models { public sealed class ForgotPasswordOptions { public const string SectionName = "Authentication:ForgotPassword"; public ForgotPasswordMethod Method { get; set; } = ForgotPasswordMethod.VerificationCode; @@ -15,4 +15,4 @@ public void Validate() { throw new InvalidOperationException("A valid absolute frontend reset URL is required for link-based password recovery."); } } -} \ No newline at end of file +} diff --git a/RuntimeApps.Authentication/Model/ForgotPasswordRequestModel.cs b/RuntimeApps.Authentication/Features/PasswordRecovery/Models/ForgotPasswordRequestModel.cs similarity index 79% rename from RuntimeApps.Authentication/Model/ForgotPasswordRequestModel.cs rename to RuntimeApps.Authentication/Features/PasswordRecovery/Models/ForgotPasswordRequestModel.cs index 7fe9f85..7e8ee76 100644 --- a/RuntimeApps.Authentication/Model/ForgotPasswordRequestModel.cs +++ b/RuntimeApps.Authentication/Features/PasswordRecovery/Models/ForgotPasswordRequestModel.cs @@ -1,6 +1,6 @@ using System.ComponentModel.DataAnnotations; -namespace RuntimeApps.Authentication.Model { +namespace RuntimeApps.Authentication.Features.PasswordRecovery.Models { /// Requests password recovery for an email address. public sealed class ForgotPasswordRequestModel { [Required] @@ -8,4 +8,4 @@ public sealed class ForgotPasswordRequestModel { [MaxLength(256)] public string Email { get; set; } } -} \ No newline at end of file +} diff --git a/RuntimeApps.Authentication/Model/ForgotPasswordResponse.cs b/RuntimeApps.Authentication/Features/PasswordRecovery/Models/ForgotPasswordResponse.cs similarity index 88% rename from RuntimeApps.Authentication/Model/ForgotPasswordResponse.cs rename to RuntimeApps.Authentication/Features/PasswordRecovery/Models/ForgotPasswordResponse.cs index d904ea7..01ef737 100644 --- a/RuntimeApps.Authentication/Model/ForgotPasswordResponse.cs +++ b/RuntimeApps.Authentication/Features/PasswordRecovery/Models/ForgotPasswordResponse.cs @@ -1,6 +1,6 @@ using System.Text.Json.Serialization; -namespace RuntimeApps.Authentication.Model { +namespace RuntimeApps.Authentication.Features.PasswordRecovery.Models { /// /// Generic response for a password-reset request. In code mode it includes an opaque /// verification handle; in link mode the handle is delivered inside the email link. @@ -11,4 +11,4 @@ public sealed class ForgotPasswordResponse { [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public string VerificationHandle { get; init; } } -} \ No newline at end of file +} diff --git a/RuntimeApps.Authentication/Model/ResetPasswordModel.cs b/RuntimeApps.Authentication/Features/PasswordRecovery/Models/ResetPasswordModel.cs similarity index 86% rename from RuntimeApps.Authentication/Model/ResetPasswordModel.cs rename to RuntimeApps.Authentication/Features/PasswordRecovery/Models/ResetPasswordModel.cs index 90aae96..dc6f64d 100644 --- a/RuntimeApps.Authentication/Model/ResetPasswordModel.cs +++ b/RuntimeApps.Authentication/Features/PasswordRecovery/Models/ResetPasswordModel.cs @@ -1,6 +1,6 @@ using System.ComponentModel.DataAnnotations; -namespace RuntimeApps.Authentication.Model { +namespace RuntimeApps.Authentication.Features.PasswordRecovery.Models { /// Completes password recovery with a verification code or link token. public sealed class ResetPasswordModel { [Required] @@ -15,4 +15,4 @@ public sealed class ResetPasswordModel { [MaxLength(1024)] public string NewPassword { get; set; } } -} \ No newline at end of file +} diff --git a/RuntimeApps.Authentication/Service/ForgotPasswordService.cs b/RuntimeApps.Authentication/Features/PasswordRecovery/Services/ForgotPasswordService.cs similarity index 93% rename from RuntimeApps.Authentication/Service/ForgotPasswordService.cs rename to RuntimeApps.Authentication/Features/PasswordRecovery/Services/ForgotPasswordService.cs index d358309..b7b046f 100644 --- a/RuntimeApps.Authentication/Service/ForgotPasswordService.cs +++ b/RuntimeApps.Authentication/Features/PasswordRecovery/Services/ForgotPasswordService.cs @@ -1,10 +1,14 @@ using Microsoft.AspNetCore.Identity; +using RuntimeApps.Authentication.Features.Verification.Services; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; -using RuntimeApps.Authentication.Interface; -using RuntimeApps.Authentication.Model; - -namespace RuntimeApps.Authentication.Service { +using RuntimeApps.Authentication.Features.PasswordRecovery.Contracts; +using RuntimeApps.Authentication.Features.RefreshTokens.Contracts; +using RuntimeApps.Authentication.Identity.Contracts; +using RuntimeApps.Authentication.Features.PasswordRecovery.Models; +using RuntimeApps.Authentication.Features.Verification.Models; +using RuntimeApps.Authentication.Shared.Models; +namespace RuntimeApps.Authentication.Features.PasswordRecovery.Services { public sealed class ForgotPasswordService : IForgotPasswordService where TUser : IdentityUser where TKey : IEquatable { @@ -124,4 +128,4 @@ public async Task ResetAsync( private static Result Failure(string code, string description) => new(ResultCode.BadRequest, Result.CreateErrors(code, description)); } -} \ No newline at end of file +} diff --git a/RuntimeApps.Authentication/Interface/IRefreshTokenService.cs b/RuntimeApps.Authentication/Features/RefreshTokens/Contracts/IRefreshTokenService.cs similarity index 83% rename from RuntimeApps.Authentication/Interface/IRefreshTokenService.cs rename to RuntimeApps.Authentication/Features/RefreshTokens/Contracts/IRefreshTokenService.cs index 4bef64c..5840cb5 100644 --- a/RuntimeApps.Authentication/Interface/IRefreshTokenService.cs +++ b/RuntimeApps.Authentication/Features/RefreshTokens/Contracts/IRefreshTokenService.cs @@ -1,6 +1,5 @@ -using RuntimeApps.Authentication.Model; - -namespace RuntimeApps.Authentication.Interface { +using RuntimeApps.Authentication.Features.RefreshTokens.Models; +namespace RuntimeApps.Authentication.Features.RefreshTokens.Contracts { public interface IRefreshTokenService where TKey : IEquatable { Task> CreateSessionAsync( @@ -14,4 +13,4 @@ Task> RotateAsync( Task RevokeAsync(string refreshToken, CancellationToken cancellationToken = default); Task RevokeAllAsync(TKey userId, CancellationToken cancellationToken = default); } -} \ No newline at end of file +} diff --git a/RuntimeApps.Authentication/Interface/IRefreshTokenStore.cs b/RuntimeApps.Authentication/Features/RefreshTokens/Contracts/IRefreshTokenStore.cs similarity index 88% rename from RuntimeApps.Authentication/Interface/IRefreshTokenStore.cs rename to RuntimeApps.Authentication/Features/RefreshTokens/Contracts/IRefreshTokenStore.cs index c256212..33cfe44 100644 --- a/RuntimeApps.Authentication/Interface/IRefreshTokenStore.cs +++ b/RuntimeApps.Authentication/Features/RefreshTokens/Contracts/IRefreshTokenStore.cs @@ -1,6 +1,5 @@ -using RuntimeApps.Authentication.Model; - -namespace RuntimeApps.Authentication.Interface { +using RuntimeApps.Authentication.Features.RefreshTokens.Models; +namespace RuntimeApps.Authentication.Features.RefreshTokens.Contracts { /// /// Persistence contract for refresh tokens. Implementations must make TryRotateAsync atomic: /// the old token must be consumed and its replacement persisted as one operation. Implementations must assign the token's Id during CreateAsync and TryRotateAsync before returning successfully. @@ -18,4 +17,4 @@ Task TryRotateAsync( Task RevokeFamilyAsync(Guid familyId, DateTimeOffset revokedAt, CancellationToken cancellationToken = default); Task RevokeAllAsync(TKey userId, DateTimeOffset revokedAt, CancellationToken cancellationToken = default); } -} \ No newline at end of file +} diff --git a/RuntimeApps.Authentication/Model/RefreshToken.cs b/RuntimeApps.Authentication/Features/RefreshTokens/Models/RefreshToken.cs similarity index 94% rename from RuntimeApps.Authentication/Model/RefreshToken.cs rename to RuntimeApps.Authentication/Features/RefreshTokens/Models/RefreshToken.cs index c1b8aef..fb6e453 100644 --- a/RuntimeApps.Authentication/Model/RefreshToken.cs +++ b/RuntimeApps.Authentication/Features/RefreshTokens/Models/RefreshToken.cs @@ -1,4 +1,4 @@ -namespace RuntimeApps.Authentication.Model { +namespace RuntimeApps.Authentication.Features.RefreshTokens.Models { /// /// Persisted refresh-token record. The raw token is never stored; only its SHA-256 hash is persisted. /// @@ -19,4 +19,4 @@ public class RefreshToken public bool HasReplacement { get; set; } public string SessionName { get; set; } } -} \ No newline at end of file +} diff --git a/RuntimeApps.Authentication/Model/RefreshTokenOptions.cs b/RuntimeApps.Authentication/Features/RefreshTokens/Models/RefreshTokenOptions.cs similarity index 94% rename from RuntimeApps.Authentication/Model/RefreshTokenOptions.cs rename to RuntimeApps.Authentication/Features/RefreshTokens/Models/RefreshTokenOptions.cs index 66ef645..02dd002 100644 --- a/RuntimeApps.Authentication/Model/RefreshTokenOptions.cs +++ b/RuntimeApps.Authentication/Features/RefreshTokens/Models/RefreshTokenOptions.cs @@ -1,6 +1,6 @@ using Microsoft.AspNetCore.Http; -namespace RuntimeApps.Authentication.Model { +namespace RuntimeApps.Authentication.Features.RefreshTokens.Models { public sealed class RefreshTokenOptions { /// Maximum lifetime of a refresh token. Defaults to 30 days. public TimeSpan TokenLifetime { get; set; } = TimeSpan.FromDays(30); @@ -23,4 +23,4 @@ public sealed class RefreshTokenOptions { /// Additional exact origins permitted to use cookie-based refresh/logout endpoints. public IList AllowedOrigins { get; set; } = new List(); } -} \ No newline at end of file +} diff --git a/RuntimeApps.Authentication/Model/RefreshTokenRequest.cs b/RuntimeApps.Authentication/Features/RefreshTokens/Models/RefreshTokenRequest.cs similarity index 87% rename from RuntimeApps.Authentication/Model/RefreshTokenRequest.cs rename to RuntimeApps.Authentication/Features/RefreshTokens/Models/RefreshTokenRequest.cs index 424a3af..39e679e 100644 --- a/RuntimeApps.Authentication/Model/RefreshTokenRequest.cs +++ b/RuntimeApps.Authentication/Features/RefreshTokens/Models/RefreshTokenRequest.cs @@ -1,6 +1,6 @@ using System.ComponentModel.DataAnnotations; -namespace RuntimeApps.Authentication.Model { +namespace RuntimeApps.Authentication.Features.RefreshTokens.Models { /// /// Request body used by JWT clients to refresh or revoke a refresh-token session. /// Cookie-authenticated clients send the refresh token in the HttpOnly cookie instead. @@ -10,4 +10,4 @@ public sealed class RefreshTokenRequest { [Required] public string RefreshToken { get; set; } } -} \ No newline at end of file +} diff --git a/RuntimeApps.Authentication/Model/RefreshTokenSession.cs b/RuntimeApps.Authentication/Features/RefreshTokens/Models/RefreshTokenSession.cs similarity index 87% rename from RuntimeApps.Authentication/Model/RefreshTokenSession.cs rename to RuntimeApps.Authentication/Features/RefreshTokens/Models/RefreshTokenSession.cs index 1413f77..bec8666 100644 --- a/RuntimeApps.Authentication/Model/RefreshTokenSession.cs +++ b/RuntimeApps.Authentication/Features/RefreshTokens/Models/RefreshTokenSession.cs @@ -1,4 +1,4 @@ -namespace RuntimeApps.Authentication.Model { +namespace RuntimeApps.Authentication.Features.RefreshTokens.Models { /// /// Result of creating or rotating a refresh-token session. Contains the raw token exactly once; /// callers must return it securely and must not log or persist it. @@ -10,4 +10,4 @@ public sealed class RefreshTokenSession public string RefreshToken { get; init; } public DateTimeOffset ExpiresAt { get; init; } } -} \ No newline at end of file +} diff --git a/RuntimeApps.Authentication/Service/RefreshTokenRequestLimiter.cs b/RuntimeApps.Authentication/Features/RefreshTokens/Services/RefreshTokenRequestLimiter.cs similarity index 91% rename from RuntimeApps.Authentication/Service/RefreshTokenRequestLimiter.cs rename to RuntimeApps.Authentication/Features/RefreshTokens/Services/RefreshTokenRequestLimiter.cs index 87ad974..961eb68 100644 --- a/RuntimeApps.Authentication/Service/RefreshTokenRequestLimiter.cs +++ b/RuntimeApps.Authentication/Features/RefreshTokens/Services/RefreshTokenRequestLimiter.cs @@ -1,9 +1,8 @@ using System.Threading.RateLimiting; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Options; -using RuntimeApps.Authentication.Model; - -namespace RuntimeApps.Authentication.Service { +using RuntimeApps.Authentication.Features.RefreshTokens.Models; +namespace RuntimeApps.Authentication.Features.RefreshTokens.Services { internal interface IRefreshTokenRequestLimiter { ValueTask IsAllowedAsync(HttpContext context, CancellationToken cancellationToken = default); } @@ -31,4 +30,4 @@ public async ValueTask IsAllowedAsync(HttpContext context, CancellationTok public void Dispose() => _limiter.Dispose(); } -} \ No newline at end of file +} diff --git a/RuntimeApps.Authentication/Service/RefreshTokenService.cs b/RuntimeApps.Authentication/Features/RefreshTokens/Services/RefreshTokenService.cs similarity index 95% rename from RuntimeApps.Authentication/Service/RefreshTokenService.cs rename to RuntimeApps.Authentication/Features/RefreshTokens/Services/RefreshTokenService.cs index 5bcf04b..17937b2 100644 --- a/RuntimeApps.Authentication/Service/RefreshTokenService.cs +++ b/RuntimeApps.Authentication/Features/RefreshTokens/Services/RefreshTokenService.cs @@ -1,11 +1,10 @@ using System.Security.Cryptography; using System.Text; using Microsoft.Extensions.Options; -using RuntimeApps.Authentication.Interface; -using RuntimeApps.Authentication.Model; - -namespace RuntimeApps.Authentication.Service { - public sealed class RefreshTokenService : IRefreshTokenService +using RuntimeApps.Authentication.Features.RefreshTokens.Contracts; +using RuntimeApps.Authentication.Features.RefreshTokens.Models; +namespace RuntimeApps.Authentication.Features.RefreshTokens.Services { + public sealed class RefreshTokenService: IRefreshTokenService where TKey : IEquatable { private readonly IRefreshTokenStore _store; private readonly RefreshTokenOptions _options; @@ -134,4 +133,4 @@ private static void ValidateSessionName(string sessionName) { throw new ArgumentException("Session name cannot exceed 100 characters.", nameof(sessionName)); } } -} \ No newline at end of file +} diff --git a/RuntimeApps.Authentication/Service/RefreshTokenStoreStartupValidator.cs b/RuntimeApps.Authentication/Features/RefreshTokens/Services/RefreshTokenStoreStartupValidator.cs similarity index 82% rename from RuntimeApps.Authentication/Service/RefreshTokenStoreStartupValidator.cs rename to RuntimeApps.Authentication/Features/RefreshTokens/Services/RefreshTokenStoreStartupValidator.cs index 19eaa9a..7dfba24 100644 --- a/RuntimeApps.Authentication/Service/RefreshTokenStoreStartupValidator.cs +++ b/RuntimeApps.Authentication/Features/RefreshTokens/Services/RefreshTokenStoreStartupValidator.cs @@ -1,9 +1,8 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; -using RuntimeApps.Authentication.Interface; - -namespace RuntimeApps.Authentication.Service { - internal sealed class RefreshTokenStoreStartupValidator : IHostedService +using RuntimeApps.Authentication.Features.RefreshTokens.Contracts; +namespace RuntimeApps.Authentication.Features.RefreshTokens.Services { + internal sealed class RefreshTokenStoreStartupValidator: IHostedService where TKey : IEquatable { private readonly IServiceScopeFactory _scopeFactory; @@ -18,4 +17,4 @@ public async Task StartAsync(CancellationToken cancellationToken) { public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask; } -} \ No newline at end of file +} diff --git a/RuntimeApps.Authentication/Interface/IRegistrationService.cs b/RuntimeApps.Authentication/Features/Registration/Contracts/IRegistrationService.cs similarity index 75% rename from RuntimeApps.Authentication/Interface/IRegistrationService.cs rename to RuntimeApps.Authentication/Features/Registration/Contracts/IRegistrationService.cs index 7b121a1..31e02bf 100644 --- a/RuntimeApps.Authentication/Interface/IRegistrationService.cs +++ b/RuntimeApps.Authentication/Features/Registration/Contracts/IRegistrationService.cs @@ -1,6 +1,6 @@ -using RuntimeApps.Authentication.Model; - -namespace RuntimeApps.Authentication.Interface { +using RuntimeApps.Authentication.Features.Registration.Models; +using RuntimeApps.Authentication.Shared.Models; +namespace RuntimeApps.Authentication.Features.Registration.Contracts { public interface IRegistrationService where TKey : IEquatable { Task> RegisterAsync( TUser user, string password, CancellationToken cancellationToken = default); @@ -11,4 +11,4 @@ Task> VerifyAsync( Task> ResendAsync( string verificationHandle, CancellationToken cancellationToken = default); } -} \ No newline at end of file +} diff --git a/RuntimeApps.Authentication/Model/RegisterUserModel.cs b/RuntimeApps.Authentication/Features/Registration/Models/RegisterUserModel.cs similarity index 71% rename from RuntimeApps.Authentication/Model/RegisterUserModel.cs rename to RuntimeApps.Authentication/Features/Registration/Models/RegisterUserModel.cs index 2e6367a..0659bfd 100644 --- a/RuntimeApps.Authentication/Model/RegisterUserModel.cs +++ b/RuntimeApps.Authentication/Features/Registration/Models/RegisterUserModel.cs @@ -1,4 +1,4 @@ -namespace RuntimeApps.Authentication.Model { +namespace RuntimeApps.Authentication.Features.Registration.Models { public class RegisterUserModel where TUser : class { public TUser UserInfo { get; set; } diff --git a/RuntimeApps.Authentication/Model/RegistrationVerificationResponse.cs b/RuntimeApps.Authentication/Features/Registration/Models/RegistrationVerificationResponse.cs similarity index 88% rename from RuntimeApps.Authentication/Model/RegistrationVerificationResponse.cs rename to RuntimeApps.Authentication/Features/Registration/Models/RegistrationVerificationResponse.cs index 718a3d6..1f62b32 100644 --- a/RuntimeApps.Authentication/Model/RegistrationVerificationResponse.cs +++ b/RuntimeApps.Authentication/Features/Registration/Models/RegistrationVerificationResponse.cs @@ -1,4 +1,4 @@ -namespace RuntimeApps.Authentication.Model { +namespace RuntimeApps.Authentication.Features.Registration.Models { public sealed class RegistrationVerificationResponse { /// /// A generic client-facing message returned for registration and resend requests. @@ -8,4 +8,4 @@ public sealed class RegistrationVerificationResponse { public string VerificationHandle { get; init; } public DateTimeOffset ExpiresAt { get; init; } } -} \ No newline at end of file +} diff --git a/RuntimeApps.Authentication/Model/ResendRegistrationVerificationModel.cs b/RuntimeApps.Authentication/Features/Registration/Models/ResendRegistrationVerificationModel.cs similarity index 63% rename from RuntimeApps.Authentication/Model/ResendRegistrationVerificationModel.cs rename to RuntimeApps.Authentication/Features/Registration/Models/ResendRegistrationVerificationModel.cs index d949482..1e5c9ba 100644 --- a/RuntimeApps.Authentication/Model/ResendRegistrationVerificationModel.cs +++ b/RuntimeApps.Authentication/Features/Registration/Models/ResendRegistrationVerificationModel.cs @@ -1,5 +1,5 @@ -namespace RuntimeApps.Authentication.Model { +namespace RuntimeApps.Authentication.Features.Registration.Models { public sealed class ResendRegistrationVerificationModel { public string VerificationHandle { get; set; } } -} \ No newline at end of file +} diff --git a/RuntimeApps.Authentication/Model/VerifyRegistrationModel.cs b/RuntimeApps.Authentication/Features/Registration/Models/VerifyRegistrationModel.cs similarity index 68% rename from RuntimeApps.Authentication/Model/VerifyRegistrationModel.cs rename to RuntimeApps.Authentication/Features/Registration/Models/VerifyRegistrationModel.cs index d3f6abb..80b0157 100644 --- a/RuntimeApps.Authentication/Model/VerifyRegistrationModel.cs +++ b/RuntimeApps.Authentication/Features/Registration/Models/VerifyRegistrationModel.cs @@ -1,6 +1,6 @@ -namespace RuntimeApps.Authentication.Model { +namespace RuntimeApps.Authentication.Features.Registration.Models { public sealed class VerifyRegistrationModel { public string VerificationHandle { get; set; } public string Code { get; set; } } -} \ No newline at end of file +} diff --git a/RuntimeApps.Authentication/Service/RegistrationService.cs b/RuntimeApps.Authentication/Features/Registration/Services/RegistrationService.cs similarity index 90% rename from RuntimeApps.Authentication/Service/RegistrationService.cs rename to RuntimeApps.Authentication/Features/Registration/Services/RegistrationService.cs index f32ffcc..a4bd9e3 100644 --- a/RuntimeApps.Authentication/Service/RegistrationService.cs +++ b/RuntimeApps.Authentication/Features/Registration/Services/RegistrationService.cs @@ -1,9 +1,14 @@ using Microsoft.AspNetCore.Identity; +using RuntimeApps.Authentication.Features.Verification.Services; using Microsoft.Extensions.Options; -using RuntimeApps.Authentication.Interface; -using RuntimeApps.Authentication.Model; - -namespace RuntimeApps.Authentication.Service { +using RuntimeApps.Authentication.Features.Account.Contracts; +using RuntimeApps.Authentication.Features.Registration.Contracts; +using RuntimeApps.Authentication.Features.Verification.Contracts; +using RuntimeApps.Authentication.Identity.Contracts; +using RuntimeApps.Authentication.Features.Registration.Models; +using RuntimeApps.Authentication.Features.Verification.Models; +using RuntimeApps.Authentication.Shared.Models; +namespace RuntimeApps.Authentication.Features.Registration.Services { public sealed class RegistrationService : IRegistrationService where TUser : IdentityUser, new() where TKey : IEquatable { @@ -106,4 +111,4 @@ private Result GenericResponse() => private static Result Failure(string code, string description) => new(ResultCode.BadRequest, Result.CreateErrors(code, description)); } -} \ No newline at end of file +} diff --git a/RuntimeApps.Authentication/Interface/IVerificationCodeGenerator.cs b/RuntimeApps.Authentication/Features/Verification/Contracts/IVerificationCodeGenerator.cs similarity index 68% rename from RuntimeApps.Authentication/Interface/IVerificationCodeGenerator.cs rename to RuntimeApps.Authentication/Features/Verification/Contracts/IVerificationCodeGenerator.cs index e4449d4..9b2419c 100644 --- a/RuntimeApps.Authentication/Interface/IVerificationCodeGenerator.cs +++ b/RuntimeApps.Authentication/Features/Verification/Contracts/IVerificationCodeGenerator.cs @@ -1,10 +1,9 @@ -using RuntimeApps.Authentication.Model; - -namespace RuntimeApps.Authentication.Interface { +using RuntimeApps.Authentication.Features.Verification.Models; +namespace RuntimeApps.Authentication.Features.Verification.Contracts { public interface IVerificationCodeGenerator where TKey : IEquatable { Task GenerateAsync( VerificationCodeContext context, VerificationOptions options, CancellationToken cancellationToken = default); } -} \ No newline at end of file +} diff --git a/RuntimeApps.Authentication/Interface/IVerificationCodeVerifier.cs b/RuntimeApps.Authentication/Features/Verification/Contracts/IVerificationCodeVerifier.cs similarity index 63% rename from RuntimeApps.Authentication/Interface/IVerificationCodeVerifier.cs rename to RuntimeApps.Authentication/Features/Verification/Contracts/IVerificationCodeVerifier.cs index 94db047..64f55c9 100644 --- a/RuntimeApps.Authentication/Interface/IVerificationCodeVerifier.cs +++ b/RuntimeApps.Authentication/Features/Verification/Contracts/IVerificationCodeVerifier.cs @@ -1,8 +1,7 @@ -using RuntimeApps.Authentication.Model; - -namespace RuntimeApps.Authentication.Interface { +using RuntimeApps.Authentication.Features.Verification.Models; +namespace RuntimeApps.Authentication.Features.Verification.Contracts { public interface IVerificationCodeVerifier where TKey : IEquatable { string CreateVerifier(string code, VerificationRequest request); bool Verify(string code, VerificationRequest request); } -} \ No newline at end of file +} diff --git a/RuntimeApps.Authentication/Interface/IVerificationRequestStore.cs b/RuntimeApps.Authentication/Features/Verification/Contracts/IVerificationRequestStore.cs similarity index 93% rename from RuntimeApps.Authentication/Interface/IVerificationRequestStore.cs rename to RuntimeApps.Authentication/Features/Verification/Contracts/IVerificationRequestStore.cs index fd09f02..cf2000d 100644 --- a/RuntimeApps.Authentication/Interface/IVerificationRequestStore.cs +++ b/RuntimeApps.Authentication/Features/Verification/Contracts/IVerificationRequestStore.cs @@ -1,6 +1,5 @@ -using RuntimeApps.Authentication.Model; - -namespace RuntimeApps.Authentication.Interface { +using RuntimeApps.Authentication.Features.Verification.Models; +namespace RuntimeApps.Authentication.Features.Verification.Contracts { /// /// Persistence contract for verification requests. State-changing methods must be atomic; /// implementations must use conditional updates or transactions to prevent replay and races. @@ -54,4 +53,4 @@ Task SupersedePendingAsync( string normalizedDestination, CancellationToken cancellationToken = default); } -} \ No newline at end of file +} diff --git a/RuntimeApps.Authentication/Interface/IVerificationSender.cs b/RuntimeApps.Authentication/Features/Verification/Contracts/IVerificationSender.cs similarity index 68% rename from RuntimeApps.Authentication/Interface/IVerificationSender.cs rename to RuntimeApps.Authentication/Features/Verification/Contracts/IVerificationSender.cs index 47ca209..d23c2d8 100644 --- a/RuntimeApps.Authentication/Interface/IVerificationSender.cs +++ b/RuntimeApps.Authentication/Features/Verification/Contracts/IVerificationSender.cs @@ -1,6 +1,5 @@ -using RuntimeApps.Authentication.Model; - -namespace RuntimeApps.Authentication.Interface { +using RuntimeApps.Authentication.Features.Verification.Models; +namespace RuntimeApps.Authentication.Features.Verification.Contracts { public interface IVerificationSender where TKey : IEquatable { Task SendAsync( VerificationCodeContext context, @@ -8,4 +7,4 @@ Task SendAsync( DateTimeOffset expiresAt, CancellationToken cancellationToken = default); } -} \ No newline at end of file +} diff --git a/RuntimeApps.Authentication/Interface/IVerificationWorkflowService.cs b/RuntimeApps.Authentication/Features/Verification/Contracts/IVerificationWorkflowService.cs similarity index 83% rename from RuntimeApps.Authentication/Interface/IVerificationWorkflowService.cs rename to RuntimeApps.Authentication/Features/Verification/Contracts/IVerificationWorkflowService.cs index 51fe2d9..4566ff7 100644 --- a/RuntimeApps.Authentication/Interface/IVerificationWorkflowService.cs +++ b/RuntimeApps.Authentication/Features/Verification/Contracts/IVerificationWorkflowService.cs @@ -1,6 +1,6 @@ -using RuntimeApps.Authentication.Model; - -namespace RuntimeApps.Authentication.Interface { +using RuntimeApps.Authentication.Features.Verification.Models; +using RuntimeApps.Authentication.Shared.Models; +namespace RuntimeApps.Authentication.Features.Verification.Contracts { public interface IVerificationWorkflowService where TKey : IEquatable { Task StartAsync( TUser user, @@ -24,4 +24,4 @@ Task> VerifyAsync( VerificationChannel expectedChannel, CancellationToken cancellationToken = default); } -} \ No newline at end of file +} diff --git a/RuntimeApps.Authentication/Model/VerificationChannel.cs b/RuntimeApps.Authentication/Features/Verification/Models/VerificationChannel.cs similarity index 75% rename from RuntimeApps.Authentication/Model/VerificationChannel.cs rename to RuntimeApps.Authentication/Features/Verification/Models/VerificationChannel.cs index ec3ecb1..1973e91 100644 --- a/RuntimeApps.Authentication/Model/VerificationChannel.cs +++ b/RuntimeApps.Authentication/Features/Verification/Models/VerificationChannel.cs @@ -1,4 +1,4 @@ -namespace RuntimeApps.Authentication.Model { +namespace RuntimeApps.Authentication.Features.Verification.Models { /// Identifies the channel used to deliver or complete a verification request. public enum VerificationChannel { Email, @@ -6,4 +6,4 @@ public enum VerificationChannel { Authenticator, Custom } -} \ No newline at end of file +} diff --git a/RuntimeApps.Authentication/Model/VerificationCodeContext.cs b/RuntimeApps.Authentication/Features/Verification/Models/VerificationCodeContext.cs similarity index 96% rename from RuntimeApps.Authentication/Model/VerificationCodeContext.cs rename to RuntimeApps.Authentication/Features/Verification/Models/VerificationCodeContext.cs index 057f512..f4c0c9c 100644 --- a/RuntimeApps.Authentication/Model/VerificationCodeContext.cs +++ b/RuntimeApps.Authentication/Features/Verification/Models/VerificationCodeContext.cs @@ -1,4 +1,4 @@ -namespace RuntimeApps.Authentication.Model { +namespace RuntimeApps.Authentication.Features.Verification.Models { public sealed class VerificationCodeContext where TKey : IEquatable { public TUser User { get; init; } public TKey UserId { get; init; } @@ -29,4 +29,4 @@ public string CreateVerificationUrl(string token) { return builder.Uri.ToString(); } } -} \ No newline at end of file +} diff --git a/RuntimeApps.Authentication/Model/VerificationOperationResult.cs b/RuntimeApps.Authentication/Features/Verification/Models/VerificationOperationResult.cs similarity index 90% rename from RuntimeApps.Authentication/Model/VerificationOperationResult.cs rename to RuntimeApps.Authentication/Features/Verification/Models/VerificationOperationResult.cs index 2281777..c46c1ee 100644 --- a/RuntimeApps.Authentication/Model/VerificationOperationResult.cs +++ b/RuntimeApps.Authentication/Features/Verification/Models/VerificationOperationResult.cs @@ -1,4 +1,4 @@ -namespace RuntimeApps.Authentication.Model { +namespace RuntimeApps.Authentication.Features.Verification.Models { public sealed class VerificationOperationResult { public bool Succeeded { get; init; } public string VerificationHandle { get; init; } @@ -12,4 +12,4 @@ public static VerificationOperationResult Success(string handle, DateTimeOffset public static VerificationOperationResult Failure(string code, string description) => new() { Succeeded = false, ErrorCode = code, ErrorDescription = description }; } -} \ No newline at end of file +} diff --git a/RuntimeApps.Authentication/Model/VerificationOptions.cs b/RuntimeApps.Authentication/Features/Verification/Models/VerificationOptions.cs similarity index 95% rename from RuntimeApps.Authentication/Model/VerificationOptions.cs rename to RuntimeApps.Authentication/Features/Verification/Models/VerificationOptions.cs index ec11201..532e132 100644 --- a/RuntimeApps.Authentication/Model/VerificationOptions.cs +++ b/RuntimeApps.Authentication/Features/Verification/Models/VerificationOptions.cs @@ -1,4 +1,4 @@ -namespace RuntimeApps.Authentication.Model { +namespace RuntimeApps.Authentication.Features.Verification.Models { public sealed class VerificationOptions { public const string SectionName = "Authentication:Verification"; @@ -27,4 +27,4 @@ public void Validate() { throw new InvalidOperationException("Maximum sends per hour must be at least one."); } } -} \ No newline at end of file +} diff --git a/RuntimeApps.Authentication/Model/VerificationPurpose.cs b/RuntimeApps.Authentication/Features/Verification/Models/VerificationPurpose.cs similarity index 78% rename from RuntimeApps.Authentication/Model/VerificationPurpose.cs rename to RuntimeApps.Authentication/Features/Verification/Models/VerificationPurpose.cs index ca087d4..99b79d0 100644 --- a/RuntimeApps.Authentication/Model/VerificationPurpose.cs +++ b/RuntimeApps.Authentication/Features/Verification/Models/VerificationPurpose.cs @@ -1,4 +1,4 @@ -namespace RuntimeApps.Authentication.Model { +namespace RuntimeApps.Authentication.Features.Verification.Models { /// Identifies the operation for which a verification request was created. public enum VerificationPurpose { Registration, @@ -8,4 +8,4 @@ public enum VerificationPurpose { PhoneChange, Custom } -} \ No newline at end of file +} diff --git a/RuntimeApps.Authentication/Model/VerificationRequest.cs b/RuntimeApps.Authentication/Features/Verification/Models/VerificationRequest.cs similarity index 94% rename from RuntimeApps.Authentication/Model/VerificationRequest.cs rename to RuntimeApps.Authentication/Features/Verification/Models/VerificationRequest.cs index cdddb0b..e55b83e 100644 --- a/RuntimeApps.Authentication/Model/VerificationRequest.cs +++ b/RuntimeApps.Authentication/Features/Verification/Models/VerificationRequest.cs @@ -1,4 +1,4 @@ -namespace RuntimeApps.Authentication.Model { +namespace RuntimeApps.Authentication.Features.Verification.Models { /// /// Persisted state for a verification operation. The raw public handle and verification code /// must never be stored in this entity. @@ -23,4 +23,4 @@ public class VerificationRequest where TKey : IEquatable { public DateTimeOffset? CompletedAt { get; set; } public VerificationRequestStatus Status { get; set; } } -} \ No newline at end of file +} diff --git a/RuntimeApps.Authentication/Model/VerificationRequestStatus.cs b/RuntimeApps.Authentication/Features/Verification/Models/VerificationRequestStatus.cs similarity index 66% rename from RuntimeApps.Authentication/Model/VerificationRequestStatus.cs rename to RuntimeApps.Authentication/Features/Verification/Models/VerificationRequestStatus.cs index b23248d..fdd1d98 100644 --- a/RuntimeApps.Authentication/Model/VerificationRequestStatus.cs +++ b/RuntimeApps.Authentication/Features/Verification/Models/VerificationRequestStatus.cs @@ -1,4 +1,4 @@ -namespace RuntimeApps.Authentication.Model { +namespace RuntimeApps.Authentication.Features.Verification.Models { public enum VerificationRequestStatus { Pending, Completed, @@ -6,4 +6,4 @@ public enum VerificationRequestStatus { Expired, Superseded } -} \ No newline at end of file +} diff --git a/RuntimeApps.Authentication/Model/VerificationSend.cs b/RuntimeApps.Authentication/Features/Verification/Models/VerificationSend.cs similarity index 85% rename from RuntimeApps.Authentication/Model/VerificationSend.cs rename to RuntimeApps.Authentication/Features/Verification/Models/VerificationSend.cs index fb41bac..4957f62 100644 --- a/RuntimeApps.Authentication/Model/VerificationSend.cs +++ b/RuntimeApps.Authentication/Features/Verification/Models/VerificationSend.cs @@ -1,4 +1,4 @@ -namespace RuntimeApps.Authentication.Model { +namespace RuntimeApps.Authentication.Features.Verification.Models { /// Immutable audit/rate-limit record for one attempted verification delivery. public sealed class VerificationSend { public long Id { get; set; } @@ -7,4 +7,4 @@ public sealed class VerificationSend { public VerificationChannel Channel { get; set; } public DateTimeOffset SentAt { get; set; } } -} \ No newline at end of file +} diff --git a/RuntimeApps.Authentication/Model/VerificationTokenGeneratorType.cs b/RuntimeApps.Authentication/Features/Verification/Models/VerificationTokenGeneratorType.cs similarity index 72% rename from RuntimeApps.Authentication/Model/VerificationTokenGeneratorType.cs rename to RuntimeApps.Authentication/Features/Verification/Models/VerificationTokenGeneratorType.cs index a729de5..fde8973 100644 --- a/RuntimeApps.Authentication/Model/VerificationTokenGeneratorType.cs +++ b/RuntimeApps.Authentication/Features/Verification/Models/VerificationTokenGeneratorType.cs @@ -1,7 +1,7 @@ -namespace RuntimeApps.Authentication.Model { +namespace RuntimeApps.Authentication.Features.Verification.Models { /// Identifies the type of credential generated for a verification request. public enum VerificationTokenGeneratorType { Code, Link } -} \ No newline at end of file +} diff --git a/RuntimeApps.Authentication/Service/DataProtectionVerificationCodeVerifier.cs b/RuntimeApps.Authentication/Features/Verification/Services/DataProtectionVerificationCodeVerifier.cs similarity index 92% rename from RuntimeApps.Authentication/Service/DataProtectionVerificationCodeVerifier.cs rename to RuntimeApps.Authentication/Features/Verification/Services/DataProtectionVerificationCodeVerifier.cs index 562ecee..e689e8b 100644 --- a/RuntimeApps.Authentication/Service/DataProtectionVerificationCodeVerifier.cs +++ b/RuntimeApps.Authentication/Features/Verification/Services/DataProtectionVerificationCodeVerifier.cs @@ -3,10 +3,10 @@ using System.Text; using System.Text.Json; using Microsoft.AspNetCore.DataProtection; -using RuntimeApps.Authentication.Interface; -using RuntimeApps.Authentication.Model; - -namespace RuntimeApps.Authentication.Service { +using RuntimeApps.Authentication.Features.Verification.Contracts; +using RuntimeApps.Authentication.Identity.Contracts; +using RuntimeApps.Authentication.Features.Verification.Models; +namespace RuntimeApps.Authentication.Features.Verification.Services { /// /// Protects verification codes with ASP.NET Core Data Protection and binds them to /// the request, user, purpose, channel, and destination. @@ -75,4 +75,4 @@ private sealed record VerificationCodePayload( string Destination, string Code); } -} \ No newline at end of file +} diff --git a/RuntimeApps.Authentication/Service/RandomVerificationCodeGenerator.cs b/RuntimeApps.Authentication/Features/Verification/Services/RandomVerificationCodeGenerator.cs similarity index 77% rename from RuntimeApps.Authentication/Service/RandomVerificationCodeGenerator.cs rename to RuntimeApps.Authentication/Features/Verification/Services/RandomVerificationCodeGenerator.cs index a764a4a..60b5265 100644 --- a/RuntimeApps.Authentication/Service/RandomVerificationCodeGenerator.cs +++ b/RuntimeApps.Authentication/Features/Verification/Services/RandomVerificationCodeGenerator.cs @@ -1,9 +1,8 @@ using System.Security.Cryptography; -using RuntimeApps.Authentication.Interface; -using RuntimeApps.Authentication.Model; - -namespace RuntimeApps.Authentication.Service { - public sealed class RandomVerificationCodeGenerator : IVerificationCodeGenerator +using RuntimeApps.Authentication.Features.Verification.Contracts; +using RuntimeApps.Authentication.Features.Verification.Models; +namespace RuntimeApps.Authentication.Features.Verification.Services { + public sealed class RandomVerificationCodeGenerator: IVerificationCodeGenerator where TKey : IEquatable { public Task GenerateAsync( VerificationCodeContext context, @@ -21,4 +20,4 @@ public Task GenerateAsync( return Task.FromResult(new string(characters)); } } -} \ No newline at end of file +} diff --git a/RuntimeApps.Authentication/Service/VerificationHandle.cs b/RuntimeApps.Authentication/Features/Verification/Services/VerificationHandle.cs similarity index 89% rename from RuntimeApps.Authentication/Service/VerificationHandle.cs rename to RuntimeApps.Authentication/Features/Verification/Services/VerificationHandle.cs index 967fe68..001df7b 100644 --- a/RuntimeApps.Authentication/Service/VerificationHandle.cs +++ b/RuntimeApps.Authentication/Features/Verification/Services/VerificationHandle.cs @@ -1,7 +1,7 @@ using System.Security.Cryptography; using System.Text; -namespace RuntimeApps.Authentication.Service { +namespace RuntimeApps.Authentication.Features.Verification.Services { /// Creates opaque public verification handles and their persisted SHA-256 lookup hashes. public static class VerificationHandle { public static string Create() => Convert.ToBase64String(RandomNumberGenerator.GetBytes(32)) @@ -14,4 +14,4 @@ public static string ComputeHash(string handle) { return Convert.ToHexString(SHA256.HashData(Encoding.UTF8.GetBytes(handle))); } } -} \ No newline at end of file +} diff --git a/RuntimeApps.Authentication/Service/VerificationWorkflowService.cs b/RuntimeApps.Authentication/Features/Verification/Services/VerificationWorkflowService.cs similarity index 97% rename from RuntimeApps.Authentication/Service/VerificationWorkflowService.cs rename to RuntimeApps.Authentication/Features/Verification/Services/VerificationWorkflowService.cs index 099c2bd..baab00e 100644 --- a/RuntimeApps.Authentication/Service/VerificationWorkflowService.cs +++ b/RuntimeApps.Authentication/Features/Verification/Services/VerificationWorkflowService.cs @@ -1,10 +1,13 @@ using System.Globalization; using Microsoft.AspNetCore.Identity; using Microsoft.Extensions.Options; -using RuntimeApps.Authentication.Interface; -using RuntimeApps.Authentication.Model; - -namespace RuntimeApps.Authentication.Service { +using RuntimeApps.Authentication.Features.PasswordRecovery.Contracts; +using RuntimeApps.Authentication.Features.Verification.Contracts; +using RuntimeApps.Authentication.Identity.Contracts; +using RuntimeApps.Authentication.Features.PasswordRecovery.Models; +using RuntimeApps.Authentication.Features.Verification.Models; +using RuntimeApps.Authentication.Shared.Models; +namespace RuntimeApps.Authentication.Features.Verification.Services { public sealed class VerificationWorkflowService : IForgotPasswordVerificationWorkflow where TUser : IdentityUser where TKey : IEquatable { @@ -232,4 +235,4 @@ private VerificationCodeContext CreateContext( private static Result Failure(string code, string description) => new(ResultCode.BadRequest, Result.CreateErrors(code, description)); } -} \ No newline at end of file +} diff --git a/RuntimeApps.Authentication/Interface/IJwtProvider.cs b/RuntimeApps.Authentication/Identity/Contracts/IJwtProvider.cs similarity index 55% rename from RuntimeApps.Authentication/Interface/IJwtProvider.cs rename to RuntimeApps.Authentication/Identity/Contracts/IJwtProvider.cs index 3a5bbdd..bff5067 100644 --- a/RuntimeApps.Authentication/Interface/IJwtProvider.cs +++ b/RuntimeApps.Authentication/Identity/Contracts/IJwtProvider.cs @@ -1,6 +1,5 @@ -using RuntimeApps.Authentication.Model; - -namespace RuntimeApps.Authentication.Interface { +using RuntimeApps.Authentication.Shared.Models; +namespace RuntimeApps.Authentication.Identity.Contracts { public interface IJwtProvider where TUser : class { Task GenerateTokenAsync(TUser user); diff --git a/RuntimeApps.Authentication/Interface/IRoleManager.cs b/RuntimeApps.Authentication/Identity/Contracts/IRoleManager.cs similarity index 88% rename from RuntimeApps.Authentication/Interface/IRoleManager.cs rename to RuntimeApps.Authentication/Identity/Contracts/IRoleManager.cs index bab3699..2af7bdb 100644 --- a/RuntimeApps.Authentication/Interface/IRoleManager.cs +++ b/RuntimeApps.Authentication/Identity/Contracts/IRoleManager.cs @@ -1,7 +1,7 @@ -using System.Security.Claims; +using System.Security.Claims; using Microsoft.AspNetCore.Identity; -namespace RuntimeApps.Authentication.Interface { +namespace RuntimeApps.Authentication.Identity.Contracts { public interface IRoleManager: IDisposable where TRole : class { IQueryable Roles { get; } Task CreateAsync(TRole role); diff --git a/RuntimeApps.Authentication/Interface/ISignInManager.cs b/RuntimeApps.Authentication/Identity/Contracts/ISignInManager.cs similarity index 96% rename from RuntimeApps.Authentication/Interface/ISignInManager.cs rename to RuntimeApps.Authentication/Identity/Contracts/ISignInManager.cs index 8b2a5a9..0b8835e 100644 --- a/RuntimeApps.Authentication/Interface/ISignInManager.cs +++ b/RuntimeApps.Authentication/Identity/Contracts/ISignInManager.cs @@ -1,8 +1,8 @@ -using System.Security.Claims; +using System.Security.Claims; using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.Identity; -namespace RuntimeApps.Authentication.Interface { +namespace RuntimeApps.Authentication.Identity.Contracts { public interface ISignInManager where TUser : class { Task CreateUserPrincipalAsync(TUser user); diff --git a/RuntimeApps.Authentication/Interface/IUserManager.cs b/RuntimeApps.Authentication/Identity/Contracts/IUserManager.cs similarity index 98% rename from RuntimeApps.Authentication/Interface/IUserManager.cs rename to RuntimeApps.Authentication/Identity/Contracts/IUserManager.cs index 0bc9280..1dd96c0 100644 --- a/RuntimeApps.Authentication/Interface/IUserManager.cs +++ b/RuntimeApps.Authentication/Identity/Contracts/IUserManager.cs @@ -1,7 +1,7 @@ -using System.Security.Claims; +using System.Security.Claims; using Microsoft.AspNetCore.Identity; -namespace RuntimeApps.Authentication.Interface { +namespace RuntimeApps.Authentication.Identity.Contracts { public interface IUserManager where TUser : class { string GetUserName(ClaimsPrincipal principal); diff --git a/RuntimeApps.Authentication/Interface/IUserMapper.cs b/RuntimeApps.Authentication/Identity/Contracts/IUserMapper.cs similarity index 91% rename from RuntimeApps.Authentication/Interface/IUserMapper.cs rename to RuntimeApps.Authentication/Identity/Contracts/IUserMapper.cs index d201082..b848623 100644 --- a/RuntimeApps.Authentication/Interface/IUserMapper.cs +++ b/RuntimeApps.Authentication/Identity/Contracts/IUserMapper.cs @@ -1,4 +1,4 @@ -namespace RuntimeApps.Authentication.Interface { +namespace RuntimeApps.Authentication.Identity.Contracts { /// /// Maps between the identity user entity and the DTO exposed by the API endpoints. /// Implement it with any mapping approach (hand-written, Mapperly, Mapster, AutoMapper, ...) diff --git a/RuntimeApps.Authentication/Service/DefaultIdentityUserMapper.cs b/RuntimeApps.Authentication/Identity/DefaultIdentityUserMapper.cs similarity index 88% rename from RuntimeApps.Authentication/Service/DefaultIdentityUserMapper.cs rename to RuntimeApps.Authentication/Identity/DefaultIdentityUserMapper.cs index 628eac8..2fc2d58 100644 --- a/RuntimeApps.Authentication/Service/DefaultIdentityUserMapper.cs +++ b/RuntimeApps.Authentication/Identity/DefaultIdentityUserMapper.cs @@ -1,8 +1,7 @@ -using Microsoft.AspNetCore.Identity; -using RuntimeApps.Authentication.Interface; -using RuntimeApps.Authentication.Model; - -namespace RuntimeApps.Authentication.Service { +using Microsoft.AspNetCore.Identity; +using RuntimeApps.Authentication.Identity.Contracts; +using RuntimeApps.Authentication.Identity.Models; +namespace RuntimeApps.Authentication.Identity { /// /// Built-in mapper between and /// (or a DTO derived from it). Override the virtual methods to map extra properties. diff --git a/RuntimeApps.Authentication/Service/DelegateUserMapper.cs b/RuntimeApps.Authentication/Identity/DelegateUserMapper.cs similarity index 89% rename from RuntimeApps.Authentication/Service/DelegateUserMapper.cs rename to RuntimeApps.Authentication/Identity/DelegateUserMapper.cs index 656f20a..bfa7911 100644 --- a/RuntimeApps.Authentication/Service/DelegateUserMapper.cs +++ b/RuntimeApps.Authentication/Identity/DelegateUserMapper.cs @@ -1,6 +1,5 @@ -using RuntimeApps.Authentication.Interface; - -namespace RuntimeApps.Authentication.Service { +using RuntimeApps.Authentication.Identity.Contracts; +namespace RuntimeApps.Authentication.Identity { /// /// backed by two delegates. /// Used by the AddUserMapper(toDto, toUser) registration overload. diff --git a/RuntimeApps.Authentication/Model/IdentityUserDto.cs b/RuntimeApps.Authentication/Identity/Models/IdentityUserDto.cs similarity index 88% rename from RuntimeApps.Authentication/Model/IdentityUserDto.cs rename to RuntimeApps.Authentication/Identity/Models/IdentityUserDto.cs index 2c4abc6..fcd2303 100644 --- a/RuntimeApps.Authentication/Model/IdentityUserDto.cs +++ b/RuntimeApps.Authentication/Identity/Models/IdentityUserDto.cs @@ -1,4 +1,4 @@ -namespace RuntimeApps.Authentication.Model { +namespace RuntimeApps.Authentication.Identity.Models { public class IdentityUserDto: IdentityUserDto { } diff --git a/RuntimeApps.Authentication/Service/RuntimeAppsRoleManager.cs b/RuntimeApps.Authentication/Identity/RuntimeAppsRoleManager.cs similarity index 76% rename from RuntimeApps.Authentication/Service/RuntimeAppsRoleManager.cs rename to RuntimeApps.Authentication/Identity/RuntimeAppsRoleManager.cs index 1cfd148..acb14c4 100644 --- a/RuntimeApps.Authentication/Service/RuntimeAppsRoleManager.cs +++ b/RuntimeApps.Authentication/Identity/RuntimeAppsRoleManager.cs @@ -1,8 +1,7 @@ -using Microsoft.AspNetCore.Identity; +using Microsoft.AspNetCore.Identity; using Microsoft.Extensions.Logging; -using RuntimeApps.Authentication.Interface; - -namespace RuntimeApps.Authentication.Service { +using RuntimeApps.Authentication.Identity.Contracts; +namespace RuntimeApps.Authentication.Identity { public class RuntimeAppsRoleManager: RoleManager, IRoleManager where TRole : class { public RuntimeAppsRoleManager(IRoleStore store, IEnumerable> roleValidators, ILookupNormalizer keyNormalizer, IdentityErrorDescriber errors, ILogger> logger) : base(store, roleValidators, keyNormalizer, errors, logger) { diff --git a/RuntimeApps.Authentication/Service/RuntimeAppsSignInManager.cs b/RuntimeApps.Authentication/Identity/RuntimeAppsSignInManager.cs similarity index 90% rename from RuntimeApps.Authentication/Service/RuntimeAppsSignInManager.cs rename to RuntimeApps.Authentication/Identity/RuntimeAppsSignInManager.cs index 82e3371..d6e2293 100644 --- a/RuntimeApps.Authentication/Service/RuntimeAppsSignInManager.cs +++ b/RuntimeApps.Authentication/Identity/RuntimeAppsSignInManager.cs @@ -1,11 +1,10 @@ -using Microsoft.AspNetCore.Authentication; +using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Identity; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; -using RuntimeApps.Authentication.Interface; - -namespace RuntimeApps.Authentication.Service { +using RuntimeApps.Authentication.Identity.Contracts; +namespace RuntimeApps.Authentication.Identity { internal class RuntimeAppsSignInManager: SignInManager, ISignInManager where TUser : class { public RuntimeAppsSignInManager(UserManager userManager, IHttpContextAccessor contextAccessor, IUserClaimsPrincipalFactory claimsFactory, IOptions optionsAccessor, ILogger> logger, IAuthenticationSchemeProvider schemes, IUserConfirmation confirmation) : base(userManager, contextAccessor, claimsFactory, optionsAccessor, logger, schemes, confirmation) { diff --git a/RuntimeApps.Authentication/Service/RuntimeAppsUserManager.cs b/RuntimeApps.Authentication/Identity/RuntimeAppsUserManager.cs similarity index 88% rename from RuntimeApps.Authentication/Service/RuntimeAppsUserManager.cs rename to RuntimeApps.Authentication/Identity/RuntimeAppsUserManager.cs index af4d69e..f0ab0f0 100644 --- a/RuntimeApps.Authentication/Service/RuntimeAppsUserManager.cs +++ b/RuntimeApps.Authentication/Identity/RuntimeAppsUserManager.cs @@ -1,9 +1,8 @@ -using Microsoft.AspNetCore.Identity; +using Microsoft.AspNetCore.Identity; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; -using RuntimeApps.Authentication.Interface; - -namespace RuntimeApps.Authentication.Service { +using RuntimeApps.Authentication.Identity.Contracts; +namespace RuntimeApps.Authentication.Identity { public class RuntimeAppsUserManager: UserManager, IUserManager where TUser : class { public RuntimeAppsUserManager(IUserStore store, diff --git a/RuntimeApps.Authentication/Extensions/IdentityResultExtensions.cs b/RuntimeApps.Authentication/Shared/Extensions/IdentityResultExtensions.cs similarity index 91% rename from RuntimeApps.Authentication/Extensions/IdentityResultExtensions.cs rename to RuntimeApps.Authentication/Shared/Extensions/IdentityResultExtensions.cs index 1a787b5..6a05050 100644 --- a/RuntimeApps.Authentication/Extensions/IdentityResultExtensions.cs +++ b/RuntimeApps.Authentication/Shared/Extensions/IdentityResultExtensions.cs @@ -1,8 +1,8 @@ -using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.HttpResults; using Microsoft.AspNetCore.Identity; -namespace RuntimeApps.Authentication.Extensions { +namespace RuntimeApps.Authentication.Shared.Extensions { public static class IdentityResultExtensions { internal static ValidationProblem CreateValidationProblem(this IdentityResult result) { var errorDictionary = new Dictionary(1); diff --git a/RuntimeApps.Authentication/Extensions/ResultExtensions.cs b/RuntimeApps.Authentication/Shared/Extensions/ResultExtensions.cs similarity index 87% rename from RuntimeApps.Authentication/Extensions/ResultExtensions.cs rename to RuntimeApps.Authentication/Shared/Extensions/ResultExtensions.cs index e820a15..484ea74 100644 --- a/RuntimeApps.Authentication/Extensions/ResultExtensions.cs +++ b/RuntimeApps.Authentication/Shared/Extensions/ResultExtensions.cs @@ -1,8 +1,7 @@ -using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.HttpResults; -using RuntimeApps.Authentication.Model; - -namespace RuntimeApps.Authentication.Extensions { +using RuntimeApps.Authentication.Shared.Models; +namespace RuntimeApps.Authentication.Shared.Extensions { public static class ResultExtensions { public static ValidationProblem CreateValidationProblem(this Result result) { var errorDictionary = new Dictionary(1); diff --git a/RuntimeApps.Authentication/Extensions/ValidationProblemFactory.cs b/RuntimeApps.Authentication/Shared/Extensions/ValidationProblemFactory.cs similarity index 80% rename from RuntimeApps.Authentication/Extensions/ValidationProblemFactory.cs rename to RuntimeApps.Authentication/Shared/Extensions/ValidationProblemFactory.cs index ff2ac0b..0cf66b9 100644 --- a/RuntimeApps.Authentication/Extensions/ValidationProblemFactory.cs +++ b/RuntimeApps.Authentication/Shared/Extensions/ValidationProblemFactory.cs @@ -1,7 +1,7 @@ -using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.HttpResults; -namespace RuntimeApps.Authentication.Extensions { +namespace RuntimeApps.Authentication.Shared.Extensions { public static class ValidationProblemFactory { internal static ValidationProblem CreateValidationProblem(string errorCode, string errorDescription) => diff --git a/RuntimeApps.Authentication/Model/ApiResult.cs b/RuntimeApps.Authentication/Shared/Models/ApiResult.cs similarity index 93% rename from RuntimeApps.Authentication/Model/ApiResult.cs rename to RuntimeApps.Authentication/Shared/Models/ApiResult.cs index dcc6798..20d7aa9 100644 --- a/RuntimeApps.Authentication/Model/ApiResult.cs +++ b/RuntimeApps.Authentication/Shared/Models/ApiResult.cs @@ -1,7 +1,7 @@ -using Microsoft.AspNetCore.Identity; +using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Mvc; -namespace RuntimeApps.Authentication.Model { +namespace RuntimeApps.Authentication.Shared.Models { public class ApiResult: ObjectResult { public ApiResult() : base(new Result()) { } diff --git a/RuntimeApps.Authentication/Model/ClaimDto.cs b/RuntimeApps.Authentication/Shared/Models/ClaimDto.cs similarity index 81% rename from RuntimeApps.Authentication/Model/ClaimDto.cs rename to RuntimeApps.Authentication/Shared/Models/ClaimDto.cs index 87f27aa..27175cc 100644 --- a/RuntimeApps.Authentication/Model/ClaimDto.cs +++ b/RuntimeApps.Authentication/Shared/Models/ClaimDto.cs @@ -1,6 +1,6 @@ -using System.Security.Claims; +using System.Security.Claims; -namespace RuntimeApps.Authentication.Model { +namespace RuntimeApps.Authentication.Shared.Models { public class ClaimDto { public string Type { get; set; } public string Value { get; set; } diff --git a/RuntimeApps.Authentication/Model/Result.cs b/RuntimeApps.Authentication/Shared/Models/Result.cs similarity index 96% rename from RuntimeApps.Authentication/Model/Result.cs rename to RuntimeApps.Authentication/Shared/Models/Result.cs index c4d1511..eb30f6c 100644 --- a/RuntimeApps.Authentication/Model/Result.cs +++ b/RuntimeApps.Authentication/Shared/Models/Result.cs @@ -1,6 +1,6 @@ -using Microsoft.AspNetCore.Identity; +using Microsoft.AspNetCore.Identity; -namespace RuntimeApps.Authentication.Model { +namespace RuntimeApps.Authentication.Shared.Models { public class Result { public static IEnumerable CreateErrors(string code, string description) => new IdentityError[]{ CreateError(code, description) diff --git a/RuntimeApps.Authentication/Model/ResultCode.cs b/RuntimeApps.Authentication/Shared/Models/ResultCode.cs similarity index 77% rename from RuntimeApps.Authentication/Model/ResultCode.cs rename to RuntimeApps.Authentication/Shared/Models/ResultCode.cs index e03dff3..e9c075a 100644 --- a/RuntimeApps.Authentication/Model/ResultCode.cs +++ b/RuntimeApps.Authentication/Shared/Models/ResultCode.cs @@ -1,4 +1,4 @@ -namespace RuntimeApps.Authentication.Model { +namespace RuntimeApps.Authentication.Shared.Models { public enum ResultCode { Success = 200, Accepted = 202, diff --git a/RuntimeApps.Authentication/Model/Token.cs b/RuntimeApps.Authentication/Shared/Models/Token.cs similarity index 95% rename from RuntimeApps.Authentication/Model/Token.cs rename to RuntimeApps.Authentication/Shared/Models/Token.cs index 29a55b6..7f0f291 100644 --- a/RuntimeApps.Authentication/Model/Token.cs +++ b/RuntimeApps.Authentication/Shared/Models/Token.cs @@ -1,6 +1,6 @@ using System.Text.Json.Serialization; -namespace RuntimeApps.Authentication.Model { +namespace RuntimeApps.Authentication.Shared.Models { public class Token { public string AuthenticationToken { get; set; } public DateTimeOffset? ExpireDate { get; set; } @@ -20,4 +20,4 @@ public class Token { [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public DateTimeOffset? VerificationExpiresAt { get; set; } } -} \ No newline at end of file +} diff --git a/Samples/RuntimeApps.Authentication.Sample.ClaimAuthorize/DbInitializer.cs b/Samples/RuntimeApps.Authentication.Sample.ClaimAuthorize/DbInitializer.cs index d046695..2d8a09a 100644 --- a/Samples/RuntimeApps.Authentication.Sample.ClaimAuthorize/DbInitializer.cs +++ b/Samples/RuntimeApps.Authentication.Sample.ClaimAuthorize/DbInitializer.cs @@ -1,8 +1,13 @@ using System.Security.Claims; using Microsoft.AspNetCore.Identity; using Microsoft.EntityFrameworkCore; -using RuntimeApps.Authentication.Interface; - +using RuntimeApps.Authentication.Features.Account.Contracts; +using RuntimeApps.Authentication.Features.ExternalLogin.Contracts; +using RuntimeApps.Authentication.Features.PasswordRecovery.Contracts; +using RuntimeApps.Authentication.Features.RefreshTokens.Contracts; +using RuntimeApps.Authentication.Features.Registration.Contracts; +using RuntimeApps.Authentication.Features.Verification.Contracts; +using RuntimeApps.Authentication.Identity.Contracts; namespace RuntimeApps.Authentication.Sample.ClaimAuthorize { public class DbInitializer { public static void Initialize(ApplicationDbContext context, IUserManager> userManager, IRoleManager> roleManager) { diff --git a/Samples/RuntimeApps.Authentication.Sample.ClaimAuthorize/Program.cs b/Samples/RuntimeApps.Authentication.Sample.ClaimAuthorize/Program.cs index a03fde3..1f5cde5 100644 --- a/Samples/RuntimeApps.Authentication.Sample.ClaimAuthorize/Program.cs +++ b/Samples/RuntimeApps.Authentication.Sample.ClaimAuthorize/Program.cs @@ -2,15 +2,34 @@ using Microsoft.AspNetCore.Authentication.JwtBearer; using Microsoft.AspNetCore.Identity; using Microsoft.EntityFrameworkCore; -using RuntimeApps.Authentication.Extensions; -using RuntimeApps.Authentication.Model; +using RuntimeApps.Authentication.DependencyInjection; +using RuntimeApps.Authentication.Shared.Extensions; +using RuntimeApps.Authentication.Features.Account.Models; +using RuntimeApps.Authentication.Features.ExternalLogin.Models; +using RuntimeApps.Authentication.Features.PasswordRecovery.Models; +using RuntimeApps.Authentication.Features.RefreshTokens.Models; +using RuntimeApps.Authentication.Features.Registration.Models; +using RuntimeApps.Authentication.Features.Verification.Models; +using RuntimeApps.Authentication.Identity.Models; +using RuntimeApps.Authentication.Shared.Models; using RuntimeApps.Authentication.Sample.ClaimAuthorize; -using RuntimeApps.Authentication.EF.Extensions; +using RuntimeApps.Authentication.EF.Features.RefreshTokens.Configurations; +using RuntimeApps.Authentication.EF.Features.Verification.Configurations; +using RuntimeApps.Authentication.EF.DependencyInjection; using System.Text.Json.Serialization; using Microsoft.IdentityModel.Tokens; -using RuntimeApps.Authentication.Interface; -using RuntimeApps.Authentication.Controller; - +using RuntimeApps.Authentication.Features.Account.Contracts; +using RuntimeApps.Authentication.Features.ExternalLogin.Contracts; +using RuntimeApps.Authentication.Features.PasswordRecovery.Contracts; +using RuntimeApps.Authentication.Features.RefreshTokens.Contracts; +using RuntimeApps.Authentication.Features.Registration.Contracts; +using RuntimeApps.Authentication.Features.Verification.Contracts; +using RuntimeApps.Authentication.Identity.Contracts; +using RuntimeApps.Authentication.Endpoints.Account; +using RuntimeApps.Authentication.Endpoints.PasswordRecovery; +using RuntimeApps.Authentication.Endpoints.RefreshTokens; +using RuntimeApps.Authentication.Endpoints.Roles; +using RuntimeApps.Authentication.Endpoints.Users; var builder = WebApplication.CreateBuilder(args); var connectionString = builder.Configuration.GetConnectionString("DefaultConnection"); diff --git a/Samples/RuntimeApps.Authentication.Sample.CookieAuthentication/ApplicationDbContext.cs b/Samples/RuntimeApps.Authentication.Sample.CookieAuthentication/ApplicationDbContext.cs index 34a512b..691c959 100644 --- a/Samples/RuntimeApps.Authentication.Sample.CookieAuthentication/ApplicationDbContext.cs +++ b/Samples/RuntimeApps.Authentication.Sample.CookieAuthentication/ApplicationDbContext.cs @@ -1,8 +1,9 @@ using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Identity.EntityFrameworkCore; using Microsoft.EntityFrameworkCore; -using RuntimeApps.Authentication.EF.Extensions; - +using RuntimeApps.Authentication.EF.Features.RefreshTokens.Configurations; +using RuntimeApps.Authentication.EF.Features.Verification.Configurations; +using RuntimeApps.Authentication.EF.DependencyInjection; namespace RuntimeApps.Authentication.Sample.CookieAuthentication { public class ApplicationDbContext: IdentityDbContext, IdentityRole, int> { public ApplicationDbContext(DbContextOptions options) : base(options) { } diff --git a/Samples/RuntimeApps.Authentication.Sample.CookieAuthentication/Migrations/ApplicationDbContextModelSnapshot.cs b/Samples/RuntimeApps.Authentication.Sample.CookieAuthentication/Migrations/ApplicationDbContextModelSnapshot.cs index 1abd791..118f546 100644 --- a/Samples/RuntimeApps.Authentication.Sample.CookieAuthentication/Migrations/ApplicationDbContextModelSnapshot.cs +++ b/Samples/RuntimeApps.Authentication.Sample.CookieAuthentication/Migrations/ApplicationDbContextModelSnapshot.cs @@ -5,8 +5,14 @@ using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; using RuntimeApps.Authentication.Sample.CookieAuthentication; -using RuntimeApps.Authentication.Model; - +using RuntimeApps.Authentication.Features.Account.Models; +using RuntimeApps.Authentication.Features.ExternalLogin.Models; +using RuntimeApps.Authentication.Features.PasswordRecovery.Models; +using RuntimeApps.Authentication.Features.RefreshTokens.Models; +using RuntimeApps.Authentication.Features.Registration.Models; +using RuntimeApps.Authentication.Features.Verification.Models; +using RuntimeApps.Authentication.Identity.Models; +using RuntimeApps.Authentication.Shared.Models; #nullable disable namespace RuntimeApps.Authentication.Sample.CookieAuthentication.Migrations diff --git a/Samples/RuntimeApps.Authentication.Sample.CookieAuthentication/Program.cs b/Samples/RuntimeApps.Authentication.Sample.CookieAuthentication/Program.cs index 84a936b..b8228fa 100644 --- a/Samples/RuntimeApps.Authentication.Sample.CookieAuthentication/Program.cs +++ b/Samples/RuntimeApps.Authentication.Sample.CookieAuthentication/Program.cs @@ -2,10 +2,24 @@ using Microsoft.AspNetCore.Authentication.JwtBearer; using Microsoft.AspNetCore.Identity; using Microsoft.EntityFrameworkCore; -using RuntimeApps.Authentication.Controller; -using RuntimeApps.Authentication.EF.Extensions; -using RuntimeApps.Authentication.Extensions; -using RuntimeApps.Authentication.Model; +using RuntimeApps.Authentication.Endpoints.Account; +using RuntimeApps.Authentication.Endpoints.PasswordRecovery; +using RuntimeApps.Authentication.Endpoints.RefreshTokens; +using RuntimeApps.Authentication.Endpoints.Roles; +using RuntimeApps.Authentication.Endpoints.Users; +using RuntimeApps.Authentication.EF.Features.RefreshTokens.Configurations; +using RuntimeApps.Authentication.EF.Features.Verification.Configurations; +using RuntimeApps.Authentication.EF.DependencyInjection; +using RuntimeApps.Authentication.DependencyInjection; +using RuntimeApps.Authentication.Shared.Extensions; +using RuntimeApps.Authentication.Features.Account.Models; +using RuntimeApps.Authentication.Features.ExternalLogin.Models; +using RuntimeApps.Authentication.Features.PasswordRecovery.Models; +using RuntimeApps.Authentication.Features.RefreshTokens.Models; +using RuntimeApps.Authentication.Features.Registration.Models; +using RuntimeApps.Authentication.Features.Verification.Models; +using RuntimeApps.Authentication.Identity.Models; +using RuntimeApps.Authentication.Shared.Models; using RuntimeApps.Authentication.Sample.CookieAuthentication; var builder = WebApplication.CreateBuilder(args); diff --git a/Samples/RuntimeApps.Authentication.Sample.CustomClaim/Program.cs b/Samples/RuntimeApps.Authentication.Sample.CustomClaim/Program.cs index f0f38ea..f3822c7 100644 --- a/Samples/RuntimeApps.Authentication.Sample.CustomClaim/Program.cs +++ b/Samples/RuntimeApps.Authentication.Sample.CustomClaim/Program.cs @@ -5,10 +5,24 @@ using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.DependencyInjection.Extensions; using Microsoft.IdentityModel.Tokens; -using RuntimeApps.Authentication.Controller; -using RuntimeApps.Authentication.EF.Extensions; -using RuntimeApps.Authentication.Extensions; -using RuntimeApps.Authentication.Model; +using RuntimeApps.Authentication.Endpoints.Account; +using RuntimeApps.Authentication.Endpoints.PasswordRecovery; +using RuntimeApps.Authentication.Endpoints.RefreshTokens; +using RuntimeApps.Authentication.Endpoints.Roles; +using RuntimeApps.Authentication.Endpoints.Users; +using RuntimeApps.Authentication.EF.Features.RefreshTokens.Configurations; +using RuntimeApps.Authentication.EF.Features.Verification.Configurations; +using RuntimeApps.Authentication.EF.DependencyInjection; +using RuntimeApps.Authentication.DependencyInjection; +using RuntimeApps.Authentication.Shared.Extensions; +using RuntimeApps.Authentication.Features.Account.Models; +using RuntimeApps.Authentication.Features.ExternalLogin.Models; +using RuntimeApps.Authentication.Features.PasswordRecovery.Models; +using RuntimeApps.Authentication.Features.RefreshTokens.Models; +using RuntimeApps.Authentication.Features.Registration.Models; +using RuntimeApps.Authentication.Features.Verification.Models; +using RuntimeApps.Authentication.Identity.Models; +using RuntimeApps.Authentication.Shared.Models; using RuntimeApps.Authentication.Sample.CustomClaim; var builder = WebApplication.CreateBuilder(args); diff --git a/Samples/RuntimeApps.Authentication.Sample.CustomModel/Program.cs b/Samples/RuntimeApps.Authentication.Sample.CustomModel/Program.cs index a28f1a8..029f18d 100644 --- a/Samples/RuntimeApps.Authentication.Sample.CustomModel/Program.cs +++ b/Samples/RuntimeApps.Authentication.Sample.CustomModel/Program.cs @@ -5,10 +5,24 @@ using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Hosting; using Microsoft.IdentityModel.Tokens; -using RuntimeApps.Authentication.Controller; -using RuntimeApps.Authentication.EF.Extensions; -using RuntimeApps.Authentication.Extensions; -using RuntimeApps.Authentication.Model; +using RuntimeApps.Authentication.Endpoints.Account; +using RuntimeApps.Authentication.Endpoints.PasswordRecovery; +using RuntimeApps.Authentication.Endpoints.RefreshTokens; +using RuntimeApps.Authentication.Endpoints.Roles; +using RuntimeApps.Authentication.Endpoints.Users; +using RuntimeApps.Authentication.EF.Features.RefreshTokens.Configurations; +using RuntimeApps.Authentication.EF.Features.Verification.Configurations; +using RuntimeApps.Authentication.EF.DependencyInjection; +using RuntimeApps.Authentication.DependencyInjection; +using RuntimeApps.Authentication.Shared.Extensions; +using RuntimeApps.Authentication.Features.Account.Models; +using RuntimeApps.Authentication.Features.ExternalLogin.Models; +using RuntimeApps.Authentication.Features.PasswordRecovery.Models; +using RuntimeApps.Authentication.Features.RefreshTokens.Models; +using RuntimeApps.Authentication.Features.Registration.Models; +using RuntimeApps.Authentication.Features.Verification.Models; +using RuntimeApps.Authentication.Identity.Models; +using RuntimeApps.Authentication.Shared.Models; using RuntimeApps.Authentication.Sample.CustomModel; var builder = WebApplication.CreateBuilder(args); diff --git a/Samples/RuntimeApps.Authentication.Sample.CustomModel/UserDto.cs b/Samples/RuntimeApps.Authentication.Sample.CustomModel/UserDto.cs index 633cbbb..04cb00b 100644 --- a/Samples/RuntimeApps.Authentication.Sample.CustomModel/UserDto.cs +++ b/Samples/RuntimeApps.Authentication.Sample.CustomModel/UserDto.cs @@ -1,5 +1,11 @@ -using RuntimeApps.Authentication.Model; - +using RuntimeApps.Authentication.Features.Account.Models; +using RuntimeApps.Authentication.Features.ExternalLogin.Models; +using RuntimeApps.Authentication.Features.PasswordRecovery.Models; +using RuntimeApps.Authentication.Features.RefreshTokens.Models; +using RuntimeApps.Authentication.Features.Registration.Models; +using RuntimeApps.Authentication.Features.Verification.Models; +using RuntimeApps.Authentication.Identity.Models; +using RuntimeApps.Authentication.Shared.Models; namespace RuntimeApps.Authentication.Sample.CustomModel { public class UserDto: IdentityUserDto { public string Name { get; set; } diff --git a/Samples/RuntimeApps.Authentication.Sample.CustomModel/UserMapper.cs b/Samples/RuntimeApps.Authentication.Sample.CustomModel/UserMapper.cs index 13493b8..c71139a 100644 --- a/Samples/RuntimeApps.Authentication.Sample.CustomModel/UserMapper.cs +++ b/Samples/RuntimeApps.Authentication.Sample.CustomModel/UserMapper.cs @@ -1,5 +1,10 @@ -using RuntimeApps.Authentication.Interface; - +using RuntimeApps.Authentication.Features.Account.Contracts; +using RuntimeApps.Authentication.Features.ExternalLogin.Contracts; +using RuntimeApps.Authentication.Features.PasswordRecovery.Contracts; +using RuntimeApps.Authentication.Features.RefreshTokens.Contracts; +using RuntimeApps.Authentication.Features.Registration.Contracts; +using RuntimeApps.Authentication.Features.Verification.Contracts; +using RuntimeApps.Authentication.Identity.Contracts; namespace RuntimeApps.Authentication.Sample.CustomModel { public class UserMapper: IUserMapper { public UserDto ToDto(User user) { diff --git a/Samples/RuntimeApps.Authentication.Sample.CustomStore/Program.cs b/Samples/RuntimeApps.Authentication.Sample.CustomStore/Program.cs index 8eea2bc..6a9dead 100644 --- a/Samples/RuntimeApps.Authentication.Sample.CustomStore/Program.cs +++ b/Samples/RuntimeApps.Authentication.Sample.CustomStore/Program.cs @@ -3,9 +3,21 @@ using Microsoft.AspNetCore.Authentication.JwtBearer; using Microsoft.AspNetCore.Identity; using Microsoft.IdentityModel.Tokens; -using RuntimeApps.Authentication.Controller; -using RuntimeApps.Authentication.Extensions; -using RuntimeApps.Authentication.Model; +using RuntimeApps.Authentication.Endpoints.Account; +using RuntimeApps.Authentication.Endpoints.PasswordRecovery; +using RuntimeApps.Authentication.Endpoints.RefreshTokens; +using RuntimeApps.Authentication.Endpoints.Roles; +using RuntimeApps.Authentication.Endpoints.Users; +using RuntimeApps.Authentication.DependencyInjection; +using RuntimeApps.Authentication.Shared.Extensions; +using RuntimeApps.Authentication.Features.Account.Models; +using RuntimeApps.Authentication.Features.ExternalLogin.Models; +using RuntimeApps.Authentication.Features.PasswordRecovery.Models; +using RuntimeApps.Authentication.Features.RefreshTokens.Models; +using RuntimeApps.Authentication.Features.Registration.Models; +using RuntimeApps.Authentication.Features.Verification.Models; +using RuntimeApps.Authentication.Identity.Models; +using RuntimeApps.Authentication.Shared.Models; using RuntimeApps.Authentication.Sample.CustomStore.Store; var builder = WebApplication.CreateBuilder(args); diff --git a/Samples/RuntimeApps.Authentication.Sample.CustomValidation/Program.cs b/Samples/RuntimeApps.Authentication.Sample.CustomValidation/Program.cs index 24be818..0a04987 100644 --- a/Samples/RuntimeApps.Authentication.Sample.CustomValidation/Program.cs +++ b/Samples/RuntimeApps.Authentication.Sample.CustomValidation/Program.cs @@ -4,10 +4,24 @@ using Microsoft.AspNetCore.Identity; using Microsoft.EntityFrameworkCore; using Microsoft.IdentityModel.Tokens; -using RuntimeApps.Authentication.Controller; -using RuntimeApps.Authentication.EF.Extensions; -using RuntimeApps.Authentication.Extensions; -using RuntimeApps.Authentication.Model; +using RuntimeApps.Authentication.Endpoints.Account; +using RuntimeApps.Authentication.Endpoints.PasswordRecovery; +using RuntimeApps.Authentication.Endpoints.RefreshTokens; +using RuntimeApps.Authentication.Endpoints.Roles; +using RuntimeApps.Authentication.Endpoints.Users; +using RuntimeApps.Authentication.EF.Features.RefreshTokens.Configurations; +using RuntimeApps.Authentication.EF.Features.Verification.Configurations; +using RuntimeApps.Authentication.EF.DependencyInjection; +using RuntimeApps.Authentication.DependencyInjection; +using RuntimeApps.Authentication.Shared.Extensions; +using RuntimeApps.Authentication.Features.Account.Models; +using RuntimeApps.Authentication.Features.ExternalLogin.Models; +using RuntimeApps.Authentication.Features.PasswordRecovery.Models; +using RuntimeApps.Authentication.Features.RefreshTokens.Models; +using RuntimeApps.Authentication.Features.Registration.Models; +using RuntimeApps.Authentication.Features.Verification.Models; +using RuntimeApps.Authentication.Identity.Models; +using RuntimeApps.Authentication.Shared.Models; using RuntimeApps.Authentication.Sample.CustomValidation; using RuntimeApps.Authentication.Sample.CustomValidation.PasswordValidators; using RuntimeApps.Authentication.Sample.CustomValidation.UserValidators; diff --git a/Samples/RuntimeApps.Authentication.Sample.RoleAuthorize/DbInitializer.cs b/Samples/RuntimeApps.Authentication.Sample.RoleAuthorize/DbInitializer.cs index bbf85f6..3fa9f09 100644 --- a/Samples/RuntimeApps.Authentication.Sample.RoleAuthorize/DbInitializer.cs +++ b/Samples/RuntimeApps.Authentication.Sample.RoleAuthorize/DbInitializer.cs @@ -1,7 +1,12 @@ using Microsoft.AspNetCore.Identity; using Microsoft.EntityFrameworkCore; -using RuntimeApps.Authentication.Interface; - +using RuntimeApps.Authentication.Features.Account.Contracts; +using RuntimeApps.Authentication.Features.ExternalLogin.Contracts; +using RuntimeApps.Authentication.Features.PasswordRecovery.Contracts; +using RuntimeApps.Authentication.Features.RefreshTokens.Contracts; +using RuntimeApps.Authentication.Features.Registration.Contracts; +using RuntimeApps.Authentication.Features.Verification.Contracts; +using RuntimeApps.Authentication.Identity.Contracts; namespace RuntimeApps.Authentication.Sample.RoleAuthorize { public static class DbInitializer { public static void Initialize(ApplicationDbContext context, IUserManager> userManager, IRoleManager> roleManager) { diff --git a/Samples/RuntimeApps.Authentication.Sample.RoleAuthorize/Program.cs b/Samples/RuntimeApps.Authentication.Sample.RoleAuthorize/Program.cs index 9ac96ac..6e4bda8 100644 --- a/Samples/RuntimeApps.Authentication.Sample.RoleAuthorize/Program.cs +++ b/Samples/RuntimeApps.Authentication.Sample.RoleAuthorize/Program.cs @@ -2,11 +2,31 @@ using Microsoft.AspNetCore.Identity; using Microsoft.EntityFrameworkCore; using Microsoft.IdentityModel.Tokens; -using RuntimeApps.Authentication.Controller; -using RuntimeApps.Authentication.EF.Extensions; -using RuntimeApps.Authentication.Extensions; -using RuntimeApps.Authentication.Interface; -using RuntimeApps.Authentication.Model; +using RuntimeApps.Authentication.Endpoints.Account; +using RuntimeApps.Authentication.Endpoints.PasswordRecovery; +using RuntimeApps.Authentication.Endpoints.RefreshTokens; +using RuntimeApps.Authentication.Endpoints.Roles; +using RuntimeApps.Authentication.Endpoints.Users; +using RuntimeApps.Authentication.EF.Features.RefreshTokens.Configurations; +using RuntimeApps.Authentication.EF.Features.Verification.Configurations; +using RuntimeApps.Authentication.EF.DependencyInjection; +using RuntimeApps.Authentication.DependencyInjection; +using RuntimeApps.Authentication.Shared.Extensions; +using RuntimeApps.Authentication.Features.Account.Contracts; +using RuntimeApps.Authentication.Features.ExternalLogin.Contracts; +using RuntimeApps.Authentication.Features.PasswordRecovery.Contracts; +using RuntimeApps.Authentication.Features.RefreshTokens.Contracts; +using RuntimeApps.Authentication.Features.Registration.Contracts; +using RuntimeApps.Authentication.Features.Verification.Contracts; +using RuntimeApps.Authentication.Identity.Contracts; +using RuntimeApps.Authentication.Features.Account.Models; +using RuntimeApps.Authentication.Features.ExternalLogin.Models; +using RuntimeApps.Authentication.Features.PasswordRecovery.Models; +using RuntimeApps.Authentication.Features.RefreshTokens.Models; +using RuntimeApps.Authentication.Features.Registration.Models; +using RuntimeApps.Authentication.Features.Verification.Models; +using RuntimeApps.Authentication.Identity.Models; +using RuntimeApps.Authentication.Shared.Models; using RuntimeApps.Authentication.Sample.RoleAuthorize; using System.Text; using System.Text.Json.Serialization; diff --git a/Samples/RuntimeApps.Authentication.Sample/ApplicationDbContext.cs b/Samples/RuntimeApps.Authentication.Sample/ApplicationDbContext.cs index b61df1f..199f380 100644 --- a/Samples/RuntimeApps.Authentication.Sample/ApplicationDbContext.cs +++ b/Samples/RuntimeApps.Authentication.Sample/ApplicationDbContext.cs @@ -1,8 +1,9 @@ using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Identity.EntityFrameworkCore; using Microsoft.EntityFrameworkCore; -using RuntimeApps.Authentication.EF.Extensions; - +using RuntimeApps.Authentication.EF.Features.RefreshTokens.Configurations; +using RuntimeApps.Authentication.EF.Features.Verification.Configurations; +using RuntimeApps.Authentication.EF.DependencyInjection; namespace RuntimeApps.Authentication.Sample { public class ApplicationDbContext: IdentityDbContext, IdentityRole, int> { diff --git a/Samples/RuntimeApps.Authentication.Sample/Program.cs b/Samples/RuntimeApps.Authentication.Sample/Program.cs index 3ff15b5..e3bba67 100644 --- a/Samples/RuntimeApps.Authentication.Sample/Program.cs +++ b/Samples/RuntimeApps.Authentication.Sample/Program.cs @@ -6,13 +6,32 @@ using RuntimeApps.Authentication.Sample.Services; using RuntimeApps.Authentication.Sample.Model; using Microsoft.IdentityModel.Tokens; -using RuntimeApps.Authentication.Controller; -using RuntimeApps.Authentication.EF.Extensions; -using RuntimeApps.Authentication.Extensions; -using RuntimeApps.Authentication.Model; +using RuntimeApps.Authentication.Endpoints.Account; +using RuntimeApps.Authentication.Endpoints.PasswordRecovery; +using RuntimeApps.Authentication.Endpoints.RefreshTokens; +using RuntimeApps.Authentication.Endpoints.Roles; +using RuntimeApps.Authentication.Endpoints.Users; +using RuntimeApps.Authentication.EF.Features.RefreshTokens.Configurations; +using RuntimeApps.Authentication.EF.Features.Verification.Configurations; +using RuntimeApps.Authentication.EF.DependencyInjection; +using RuntimeApps.Authentication.DependencyInjection; +using RuntimeApps.Authentication.Shared.Extensions; +using RuntimeApps.Authentication.Features.Account.Models; +using RuntimeApps.Authentication.Features.ExternalLogin.Models; +using RuntimeApps.Authentication.Features.PasswordRecovery.Models; +using RuntimeApps.Authentication.Features.RefreshTokens.Models; +using RuntimeApps.Authentication.Features.Registration.Models; +using RuntimeApps.Authentication.Features.Verification.Models; +using RuntimeApps.Authentication.Identity.Models; +using RuntimeApps.Authentication.Shared.Models; using RuntimeApps.Authentication.Sample; -using RuntimeApps.Authentication.Interface; - +using RuntimeApps.Authentication.Features.Account.Contracts; +using RuntimeApps.Authentication.Features.ExternalLogin.Contracts; +using RuntimeApps.Authentication.Features.PasswordRecovery.Contracts; +using RuntimeApps.Authentication.Features.RefreshTokens.Contracts; +using RuntimeApps.Authentication.Features.Registration.Contracts; +using RuntimeApps.Authentication.Features.Verification.Contracts; +using RuntimeApps.Authentication.Identity.Contracts; var builder = WebApplication.CreateBuilder(args); builder.Services.AddDbContext(options => diff --git a/Samples/RuntimeApps.Authentication.Sample/Services/MailKitVerificationSender.cs b/Samples/RuntimeApps.Authentication.Sample/Services/MailKitVerificationSender.cs index ec479af..b61cecf 100644 --- a/Samples/RuntimeApps.Authentication.Sample/Services/MailKitVerificationSender.cs +++ b/Samples/RuntimeApps.Authentication.Sample/Services/MailKitVerificationSender.cs @@ -1,10 +1,22 @@ using MailKit.Net.Smtp; using Microsoft.Extensions.Options; using MimeKit; -using RuntimeApps.Authentication.Interface; +using RuntimeApps.Authentication.Features.Account.Contracts; +using RuntimeApps.Authentication.Features.ExternalLogin.Contracts; +using RuntimeApps.Authentication.Features.PasswordRecovery.Contracts; +using RuntimeApps.Authentication.Features.RefreshTokens.Contracts; +using RuntimeApps.Authentication.Features.Registration.Contracts; +using RuntimeApps.Authentication.Features.Verification.Contracts; +using RuntimeApps.Authentication.Identity.Contracts; using RuntimeApps.Authentication.Sample.Model; -using RuntimeApps.Authentication.Model; - +using RuntimeApps.Authentication.Features.Account.Models; +using RuntimeApps.Authentication.Features.ExternalLogin.Models; +using RuntimeApps.Authentication.Features.PasswordRecovery.Models; +using RuntimeApps.Authentication.Features.RefreshTokens.Models; +using RuntimeApps.Authentication.Features.Registration.Models; +using RuntimeApps.Authentication.Features.Verification.Models; +using RuntimeApps.Authentication.Identity.Models; +using RuntimeApps.Authentication.Shared.Models; namespace RuntimeApps.Authentication.Sample.Services { public sealed class MailKitVerificationSender : IVerificationSender where TKey : IEquatable { diff --git a/Tests/RuntimeApps.Authentication.Test/EfRefreshTokenStoreTest.cs b/Tests/RuntimeApps.Authentication.Test/EfRefreshTokenStoreTest.cs index 5c658f8..4472a19 100644 --- a/Tests/RuntimeApps.Authentication.Test/EfRefreshTokenStoreTest.cs +++ b/Tests/RuntimeApps.Authentication.Test/EfRefreshTokenStoreTest.cs @@ -2,10 +2,19 @@ using Microsoft.AspNetCore.Identity.EntityFrameworkCore; using Microsoft.Data.Sqlite; using Microsoft.EntityFrameworkCore; -using RuntimeApps.Authentication.EF.Extensions; -using RuntimeApps.Authentication.EF.Store; -using RuntimeApps.Authentication.Model; - +using RuntimeApps.Authentication.EF.Features.RefreshTokens.Configurations; +using RuntimeApps.Authentication.EF.Features.Verification.Configurations; +using RuntimeApps.Authentication.EF.DependencyInjection; +using RuntimeApps.Authentication.EF.Features.RefreshTokens.Stores; +using RuntimeApps.Authentication.EF.Features.Verification.Stores; +using RuntimeApps.Authentication.Features.Account.Models; +using RuntimeApps.Authentication.Features.ExternalLogin.Models; +using RuntimeApps.Authentication.Features.PasswordRecovery.Models; +using RuntimeApps.Authentication.Features.RefreshTokens.Models; +using RuntimeApps.Authentication.Features.Registration.Models; +using RuntimeApps.Authentication.Features.Verification.Models; +using RuntimeApps.Authentication.Identity.Models; +using RuntimeApps.Authentication.Shared.Models; namespace RuntimeApps.Authentication.Test { public class EfRefreshTokenStoreTest { [Fact] diff --git a/Tests/RuntimeApps.Authentication.Test/EfVerificationRequestStoreTest.cs b/Tests/RuntimeApps.Authentication.Test/EfVerificationRequestStoreTest.cs index 4212e2a..d724757 100644 --- a/Tests/RuntimeApps.Authentication.Test/EfVerificationRequestStoreTest.cs +++ b/Tests/RuntimeApps.Authentication.Test/EfVerificationRequestStoreTest.cs @@ -2,10 +2,19 @@ using Microsoft.AspNetCore.Identity.EntityFrameworkCore; using Microsoft.Data.Sqlite; using Microsoft.EntityFrameworkCore; -using RuntimeApps.Authentication.EF.Extensions; -using RuntimeApps.Authentication.EF.Store; -using RuntimeApps.Authentication.Model; - +using RuntimeApps.Authentication.EF.Features.RefreshTokens.Configurations; +using RuntimeApps.Authentication.EF.Features.Verification.Configurations; +using RuntimeApps.Authentication.EF.DependencyInjection; +using RuntimeApps.Authentication.EF.Features.RefreshTokens.Stores; +using RuntimeApps.Authentication.EF.Features.Verification.Stores; +using RuntimeApps.Authentication.Features.Account.Models; +using RuntimeApps.Authentication.Features.ExternalLogin.Models; +using RuntimeApps.Authentication.Features.PasswordRecovery.Models; +using RuntimeApps.Authentication.Features.RefreshTokens.Models; +using RuntimeApps.Authentication.Features.Registration.Models; +using RuntimeApps.Authentication.Features.Verification.Models; +using RuntimeApps.Authentication.Identity.Models; +using RuntimeApps.Authentication.Shared.Models; namespace RuntimeApps.Authentication.Test { public class EfVerificationRequestStoreTest { [Fact] diff --git a/Tests/RuntimeApps.Authentication.Test/ExternalLoginEmailTrustPolicyTest.cs b/Tests/RuntimeApps.Authentication.Test/ExternalLoginEmailTrustPolicyTest.cs index ee0276c..370e62f 100644 --- a/Tests/RuntimeApps.Authentication.Test/ExternalLoginEmailTrustPolicyTest.cs +++ b/Tests/RuntimeApps.Authentication.Test/ExternalLoginEmailTrustPolicyTest.cs @@ -1,6 +1,19 @@ -using RuntimeApps.Authentication.Model; -using RuntimeApps.Authentication.Service; - +using RuntimeApps.Authentication.Features.Account.Models; +using RuntimeApps.Authentication.Features.ExternalLogin.Models; +using RuntimeApps.Authentication.Features.PasswordRecovery.Models; +using RuntimeApps.Authentication.Features.RefreshTokens.Models; +using RuntimeApps.Authentication.Features.Registration.Models; +using RuntimeApps.Authentication.Features.Verification.Models; +using RuntimeApps.Authentication.Identity.Models; +using RuntimeApps.Authentication.Shared.Models; +using RuntimeApps.Authentication.Features.Account.Services; +using RuntimeApps.Authentication.Features.ExternalLogin.Providers; +using RuntimeApps.Authentication.Features.ExternalLogin.Services; +using RuntimeApps.Authentication.Features.PasswordRecovery.Services; +using RuntimeApps.Authentication.Features.RefreshTokens.Services; +using RuntimeApps.Authentication.Features.Registration.Services; +using RuntimeApps.Authentication.Features.Verification.Services; +using RuntimeApps.Authentication.Identity; namespace RuntimeApps.Authentication.Test { public class ExternalLoginEmailTrustPolicyTest { private readonly DefaultExternalLoginEmailTrustPolicy _policy = new(); diff --git a/Tests/RuntimeApps.Authentication.Test/ForgotPasswordOptionsTest.cs b/Tests/RuntimeApps.Authentication.Test/ForgotPasswordOptionsTest.cs index 3b3198f..ad5a5bb 100644 --- a/Tests/RuntimeApps.Authentication.Test/ForgotPasswordOptionsTest.cs +++ b/Tests/RuntimeApps.Authentication.Test/ForgotPasswordOptionsTest.cs @@ -2,8 +2,16 @@ using Microsoft.AspNetCore.Identity; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; -using RuntimeApps.Authentication.Extensions; -using RuntimeApps.Authentication.Model; +using RuntimeApps.Authentication.DependencyInjection; +using RuntimeApps.Authentication.Shared.Extensions; +using RuntimeApps.Authentication.Features.Account.Models; +using RuntimeApps.Authentication.Features.ExternalLogin.Models; +using RuntimeApps.Authentication.Features.PasswordRecovery.Models; +using RuntimeApps.Authentication.Features.RefreshTokens.Models; +using RuntimeApps.Authentication.Features.Registration.Models; +using RuntimeApps.Authentication.Features.Verification.Models; +using RuntimeApps.Authentication.Identity.Models; +using RuntimeApps.Authentication.Shared.Models; using Xunit; namespace RuntimeApps.Authentication.Test { diff --git a/Tests/RuntimeApps.Authentication.Test/ForgotPasswordServiceTest.cs b/Tests/RuntimeApps.Authentication.Test/ForgotPasswordServiceTest.cs index dd06b11..22f4c75 100644 --- a/Tests/RuntimeApps.Authentication.Test/ForgotPasswordServiceTest.cs +++ b/Tests/RuntimeApps.Authentication.Test/ForgotPasswordServiceTest.cs @@ -3,9 +3,29 @@ using Microsoft.Extensions.Logging.Abstractions; using Microsoft.Extensions.Options; using Moq; -using RuntimeApps.Authentication.Interface; -using RuntimeApps.Authentication.Model; -using RuntimeApps.Authentication.Service; +using RuntimeApps.Authentication.Features.Account.Contracts; +using RuntimeApps.Authentication.Features.ExternalLogin.Contracts; +using RuntimeApps.Authentication.Features.PasswordRecovery.Contracts; +using RuntimeApps.Authentication.Features.RefreshTokens.Contracts; +using RuntimeApps.Authentication.Features.Registration.Contracts; +using RuntimeApps.Authentication.Features.Verification.Contracts; +using RuntimeApps.Authentication.Identity.Contracts; +using RuntimeApps.Authentication.Features.Account.Models; +using RuntimeApps.Authentication.Features.ExternalLogin.Models; +using RuntimeApps.Authentication.Features.PasswordRecovery.Models; +using RuntimeApps.Authentication.Features.RefreshTokens.Models; +using RuntimeApps.Authentication.Features.Registration.Models; +using RuntimeApps.Authentication.Features.Verification.Models; +using RuntimeApps.Authentication.Identity.Models; +using RuntimeApps.Authentication.Shared.Models; +using RuntimeApps.Authentication.Features.Account.Services; +using RuntimeApps.Authentication.Features.ExternalLogin.Providers; +using RuntimeApps.Authentication.Features.ExternalLogin.Services; +using RuntimeApps.Authentication.Features.PasswordRecovery.Services; +using RuntimeApps.Authentication.Features.RefreshTokens.Services; +using RuntimeApps.Authentication.Features.Registration.Services; +using RuntimeApps.Authentication.Features.Verification.Services; +using RuntimeApps.Authentication.Identity; using Xunit; namespace RuntimeApps.Authentication.Test { diff --git a/Tests/RuntimeApps.Authentication.Test/RefreshTokenRegistrationTest.cs b/Tests/RuntimeApps.Authentication.Test/RefreshTokenRegistrationTest.cs index d4260d6..c608f56 100644 --- a/Tests/RuntimeApps.Authentication.Test/RefreshTokenRegistrationTest.cs +++ b/Tests/RuntimeApps.Authentication.Test/RefreshTokenRegistrationTest.cs @@ -1,9 +1,15 @@ using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.Identity; using Microsoft.Extensions.DependencyInjection; -using RuntimeApps.Authentication.Extensions; -using RuntimeApps.Authentication.Interface; - +using RuntimeApps.Authentication.DependencyInjection; +using RuntimeApps.Authentication.Shared.Extensions; +using RuntimeApps.Authentication.Features.Account.Contracts; +using RuntimeApps.Authentication.Features.ExternalLogin.Contracts; +using RuntimeApps.Authentication.Features.PasswordRecovery.Contracts; +using RuntimeApps.Authentication.Features.RefreshTokens.Contracts; +using RuntimeApps.Authentication.Features.Registration.Contracts; +using RuntimeApps.Authentication.Features.Verification.Contracts; +using RuntimeApps.Authentication.Identity.Contracts; namespace RuntimeApps.Authentication.Test { public class RefreshTokenRegistrationTest { [Fact] diff --git a/Tests/RuntimeApps.Authentication.Test/RefreshTokenServiceTest.cs b/Tests/RuntimeApps.Authentication.Test/RefreshTokenServiceTest.cs index 5ac6856..b229eac 100644 --- a/Tests/RuntimeApps.Authentication.Test/RefreshTokenServiceTest.cs +++ b/Tests/RuntimeApps.Authentication.Test/RefreshTokenServiceTest.cs @@ -1,8 +1,27 @@ using Microsoft.Extensions.Options; -using RuntimeApps.Authentication.Interface; -using RuntimeApps.Authentication.Model; -using RuntimeApps.Authentication.Service; - +using RuntimeApps.Authentication.Features.Account.Contracts; +using RuntimeApps.Authentication.Features.ExternalLogin.Contracts; +using RuntimeApps.Authentication.Features.PasswordRecovery.Contracts; +using RuntimeApps.Authentication.Features.RefreshTokens.Contracts; +using RuntimeApps.Authentication.Features.Registration.Contracts; +using RuntimeApps.Authentication.Features.Verification.Contracts; +using RuntimeApps.Authentication.Identity.Contracts; +using RuntimeApps.Authentication.Features.Account.Models; +using RuntimeApps.Authentication.Features.ExternalLogin.Models; +using RuntimeApps.Authentication.Features.PasswordRecovery.Models; +using RuntimeApps.Authentication.Features.RefreshTokens.Models; +using RuntimeApps.Authentication.Features.Registration.Models; +using RuntimeApps.Authentication.Features.Verification.Models; +using RuntimeApps.Authentication.Identity.Models; +using RuntimeApps.Authentication.Shared.Models; +using RuntimeApps.Authentication.Features.Account.Services; +using RuntimeApps.Authentication.Features.ExternalLogin.Providers; +using RuntimeApps.Authentication.Features.ExternalLogin.Services; +using RuntimeApps.Authentication.Features.PasswordRecovery.Services; +using RuntimeApps.Authentication.Features.RefreshTokens.Services; +using RuntimeApps.Authentication.Features.Registration.Services; +using RuntimeApps.Authentication.Features.Verification.Services; +using RuntimeApps.Authentication.Identity; namespace RuntimeApps.Authentication.Test { public class RefreshTokenServiceTest { private readonly InMemoryRefreshTokenStore _store = new(); diff --git a/Tests/RuntimeApps.Authentication.Test/RegistrationServiceTest.cs b/Tests/RuntimeApps.Authentication.Test/RegistrationServiceTest.cs index abc1880..da07a9b 100644 --- a/Tests/RuntimeApps.Authentication.Test/RegistrationServiceTest.cs +++ b/Tests/RuntimeApps.Authentication.Test/RegistrationServiceTest.cs @@ -1,10 +1,29 @@ using Microsoft.AspNetCore.Identity; using Microsoft.Extensions.Options; using Moq; -using RuntimeApps.Authentication.Interface; -using RuntimeApps.Authentication.Model; -using RuntimeApps.Authentication.Service; - +using RuntimeApps.Authentication.Features.Account.Contracts; +using RuntimeApps.Authentication.Features.ExternalLogin.Contracts; +using RuntimeApps.Authentication.Features.PasswordRecovery.Contracts; +using RuntimeApps.Authentication.Features.RefreshTokens.Contracts; +using RuntimeApps.Authentication.Features.Registration.Contracts; +using RuntimeApps.Authentication.Features.Verification.Contracts; +using RuntimeApps.Authentication.Identity.Contracts; +using RuntimeApps.Authentication.Features.Account.Models; +using RuntimeApps.Authentication.Features.ExternalLogin.Models; +using RuntimeApps.Authentication.Features.PasswordRecovery.Models; +using RuntimeApps.Authentication.Features.RefreshTokens.Models; +using RuntimeApps.Authentication.Features.Registration.Models; +using RuntimeApps.Authentication.Features.Verification.Models; +using RuntimeApps.Authentication.Identity.Models; +using RuntimeApps.Authentication.Shared.Models; +using RuntimeApps.Authentication.Features.Account.Services; +using RuntimeApps.Authentication.Features.ExternalLogin.Providers; +using RuntimeApps.Authentication.Features.ExternalLogin.Services; +using RuntimeApps.Authentication.Features.PasswordRecovery.Services; +using RuntimeApps.Authentication.Features.RefreshTokens.Services; +using RuntimeApps.Authentication.Features.Registration.Services; +using RuntimeApps.Authentication.Features.Verification.Services; +using RuntimeApps.Authentication.Identity; namespace RuntimeApps.Authentication.Test { public class RegistrationServiceTest { [Fact] diff --git a/Tests/RuntimeApps.Authentication.Test/UserAccountServiceTest.cs b/Tests/RuntimeApps.Authentication.Test/UserAccountServiceTest.cs index 7aa84a3..badd6f2 100644 --- a/Tests/RuntimeApps.Authentication.Test/UserAccountServiceTest.cs +++ b/Tests/RuntimeApps.Authentication.Test/UserAccountServiceTest.cs @@ -3,9 +3,21 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Identity; using Moq; -using RuntimeApps.Authentication.Interface; -using RuntimeApps.Authentication.Service; - +using RuntimeApps.Authentication.Features.Account.Contracts; +using RuntimeApps.Authentication.Features.ExternalLogin.Contracts; +using RuntimeApps.Authentication.Features.PasswordRecovery.Contracts; +using RuntimeApps.Authentication.Features.RefreshTokens.Contracts; +using RuntimeApps.Authentication.Features.Registration.Contracts; +using RuntimeApps.Authentication.Features.Verification.Contracts; +using RuntimeApps.Authentication.Identity.Contracts; +using RuntimeApps.Authentication.Features.Account.Services; +using RuntimeApps.Authentication.Features.ExternalLogin.Providers; +using RuntimeApps.Authentication.Features.ExternalLogin.Services; +using RuntimeApps.Authentication.Features.PasswordRecovery.Services; +using RuntimeApps.Authentication.Features.RefreshTokens.Services; +using RuntimeApps.Authentication.Features.Registration.Services; +using RuntimeApps.Authentication.Features.Verification.Services; +using RuntimeApps.Authentication.Identity; namespace RuntimeApps.Authentication.Test { public class UserAccountServiceTest { private const IdentityUser nullUSer = null; @@ -55,7 +67,7 @@ public async Task Login_Success() { UserName = userName, EmailConfirmed = true }; - var token = new Model.Token() { + var token = new RuntimeApps.Authentication.Shared.Models.Token() { AuthenticationToken = "", ExpireDate = DateTimeOffset.Now.AddDays(30), }; @@ -131,7 +143,7 @@ public async Task Login_WrongPassword() { [Fact] public async Task CompleteRegistration_Success_ConfirmedUser() { var user = new IdentityUser { Email = "test@test.com", EmailConfirmed = true }; - var token = new Model.Token { + var token = new RuntimeApps.Authentication.Shared.Models.Token { AuthenticationToken = "", ExpireDate = DateTimeOffset.Now.AddDays(30), }; @@ -151,7 +163,7 @@ public async Task CompleteRegistration_UnconfirmedUser_IsRejected() { var result = await _userAccountService.CompleteRegistrationAsync(user); result.Succeeded.Should().BeFalse(); - result.Code.Should().Be(RuntimeApps.Authentication.Model.ResultCode.Forbidden); + result.Code.Should().Be(RuntimeApps.Authentication.Shared.Models.ResultCode.Forbidden); _jwtProviderMock.Verify(provider => provider.GenerateTokenAsync(It.IsAny()), Times.Never()); } @@ -162,7 +174,7 @@ public async Task ExternalLogin_Success_CreateNewUser() { var user = new IdentityUser() { Email = "test@test.com" }; - var appToken = new Model.Token() { + var appToken = new RuntimeApps.Authentication.Shared.Models.Token() { AuthenticationToken = "", ExpireDate = DateTimeOffset.Now.AddDays(30), }; @@ -172,7 +184,7 @@ public async Task ExternalLogin_Success_CreateNewUser() { _externalLoginProvider2.SetupGet(e => e.Provider) .Returns(provider); _externalLoginProvider2.Setup(e => e.ValidateAsync(token)) - .ReturnsAsync(new RuntimeApps.Authentication.Model.ExternalLoginProviderResult { + .ReturnsAsync(new RuntimeApps.Authentication.Features.ExternalLogin.Models.ExternalLoginProviderResult { User = user, LoginInfo = loginInfo, Email = user.Email, EmailVerified = false }); _userManagerMock.Setup(u => u.FindByLoginAsync(provider, token)) @@ -208,7 +220,7 @@ public async Task ExternalLogin_ExistingEmail_DoesNotAutomaticallyLink() { _externalLoginProvider1.SetupGet(item => item.Provider).Returns("Not Selected"); _externalLoginProvider2.SetupGet(item => item.Provider).Returns(provider); _externalLoginProvider2.Setup(item => item.ValidateAsync(token)) - .ReturnsAsync(new RuntimeApps.Authentication.Model.ExternalLoginProviderResult { + .ReturnsAsync(new RuntimeApps.Authentication.Features.ExternalLogin.Models.ExternalLoginProviderResult { User = new IdentityUser { Email = existingUser.Email }, LoginInfo = loginInfo, Email = existingUser.Email, @@ -220,7 +232,7 @@ public async Task ExternalLogin_ExistingEmail_DoesNotAutomaticallyLink() { var result = await _userAccountService.ExternalLoginAsync(provider, token); Assert.False(result.Succeeded); - Assert.Equal(RuntimeApps.Authentication.Model.ResultCode.Conflict, result.Code); + Assert.Equal(RuntimeApps.Authentication.Shared.Models.ResultCode.Conflict, result.Code); _userManagerMock.Verify(manager => manager.AddLoginAsync(It.IsAny(), It.IsAny()), Times.Never()); } @@ -233,7 +245,7 @@ public async Task ExternalLogin_UnverifiedEmail_DoesNotLinkExistingAccount() { _externalLoginProvider1.SetupGet(item => item.Provider).Returns("Not Selected"); _externalLoginProvider2.SetupGet(item => item.Provider).Returns(provider); _externalLoginProvider2.Setup(item => item.ValidateAsync(token)) - .ReturnsAsync(new RuntimeApps.Authentication.Model.ExternalLoginProviderResult { + .ReturnsAsync(new RuntimeApps.Authentication.Features.ExternalLogin.Models.ExternalLoginProviderResult { User = new IdentityUser { Email = user.Email }, LoginInfo = loginInfo, Email = user.Email, EmailVerified = false }); @@ -243,7 +255,7 @@ public async Task ExternalLogin_UnverifiedEmail_DoesNotLinkExistingAccount() { var result = await _userAccountService.ExternalLoginAsync(provider, token); Assert.False(result.Succeeded); - Assert.Equal(RuntimeApps.Authentication.Model.ResultCode.Conflict, result.Code); + Assert.Equal(RuntimeApps.Authentication.Shared.Models.ResultCode.Conflict, result.Code); _userManagerMock.Verify(manager => manager.AddLoginAsync(It.IsAny(), It.IsAny()), Times.Never()); } @@ -259,7 +271,7 @@ public async Task ExternalLogin_CanRequireEmailVerificationWithoutIssuingToken() _externalLoginProvider1.SetupGet(item => item.Provider).Returns("Not Selected"); _externalLoginProvider2.SetupGet(item => item.Provider).Returns(provider); _externalLoginProvider2.Setup(item => item.ValidateAsync(token)) - .ReturnsAsync(new RuntimeApps.Authentication.Model.ExternalLoginProviderResult { + .ReturnsAsync(new RuntimeApps.Authentication.Features.ExternalLogin.Models.ExternalLoginProviderResult { User = user, LoginInfo = loginInfo, Email = user.Email, EmailVerified = false }); _userManagerMock.Setup(manager => manager.FindByLoginAsync(provider, token)).ReturnsAsync((IdentityUser)null); @@ -267,10 +279,10 @@ public async Task ExternalLogin_CanRequireEmailVerificationWithoutIssuingToken() _userManagerMock.Setup(manager => manager.CreateAsync(user)).ReturnsAsync(IdentityResult.Success); _userManagerMock.Setup(manager => manager.AddLoginAsync(user, loginInfo)).ReturnsAsync(IdentityResult.Success); workflow.Setup(service => service.StartAsync( - user, RuntimeApps.Authentication.Model.VerificationPurpose.Registration, - RuntimeApps.Authentication.Model.VerificationChannel.Email, user.Email, + user, RuntimeApps.Authentication.Features.Verification.Models.VerificationPurpose.Registration, + RuntimeApps.Authentication.Features.Verification.Models.VerificationChannel.Email, user.Email, null, null, It.IsAny())) - .ReturnsAsync(RuntimeApps.Authentication.Model.VerificationOperationResult.Success("external-handle", expiresAt)); + .ReturnsAsync(RuntimeApps.Authentication.Features.Verification.Models.VerificationOperationResult.Success("external-handle", expiresAt)); var service = new UserAccountService( _userManagerMock.Object, _signInManagerMock.Object, @@ -278,7 +290,7 @@ public async Task ExternalLogin_CanRequireEmailVerificationWithoutIssuingToken() _authenticationHandlerProviderMock.Object, _httpContextAccessorMock.Object, _userClaimsPrincipalFactoryMock.Object, _authenticationSchemeProviderMock.Object, _jwtProviderMock.Object, null, null, _externalLoginEmailTrustPolicyMock.Object, - Microsoft.Extensions.Options.Options.Create(new RuntimeApps.Authentication.Model.VerificationOptions { + Microsoft.Extensions.Options.Options.Create(new RuntimeApps.Authentication.Features.Verification.Models.VerificationOptions { RequireEmailVerificationForExternalLogins = true }), workflow.Object); @@ -298,7 +310,7 @@ public async Task ExternalLogin_Success_ExistsLogin() { var user = new IdentityUser() { Email = "test@test.com" }; - var appToken = new Model.Token() { + var appToken = new RuntimeApps.Authentication.Shared.Models.Token() { AuthenticationToken = "", ExpireDate = DateTimeOffset.Now.AddDays(30), }; @@ -308,7 +320,7 @@ public async Task ExternalLogin_Success_ExistsLogin() { _externalLoginProvider2.SetupGet(e => e.Provider) .Returns(provider); _externalLoginProvider2.Setup(e => e.ValidateAsync(token)) - .ReturnsAsync(new RuntimeApps.Authentication.Model.ExternalLoginProviderResult { + .ReturnsAsync(new RuntimeApps.Authentication.Features.ExternalLogin.Models.ExternalLoginProviderResult { User = user, LoginInfo = loginInfo, Email = user.Email, EmailVerified = false }); _userManagerMock.Setup(u => u.FindByLoginAsync(provider, token)) diff --git a/Tests/RuntimeApps.Authentication.Test/VerificationPrimitivesTest.cs b/Tests/RuntimeApps.Authentication.Test/VerificationPrimitivesTest.cs index 3588fac..82e18a7 100644 --- a/Tests/RuntimeApps.Authentication.Test/VerificationPrimitivesTest.cs +++ b/Tests/RuntimeApps.Authentication.Test/VerificationPrimitivesTest.cs @@ -1,8 +1,21 @@ using Microsoft.AspNetCore.DataProtection; using Microsoft.Extensions.DependencyInjection; -using RuntimeApps.Authentication.Model; -using RuntimeApps.Authentication.Service; - +using RuntimeApps.Authentication.Features.Account.Models; +using RuntimeApps.Authentication.Features.ExternalLogin.Models; +using RuntimeApps.Authentication.Features.PasswordRecovery.Models; +using RuntimeApps.Authentication.Features.RefreshTokens.Models; +using RuntimeApps.Authentication.Features.Registration.Models; +using RuntimeApps.Authentication.Features.Verification.Models; +using RuntimeApps.Authentication.Identity.Models; +using RuntimeApps.Authentication.Shared.Models; +using RuntimeApps.Authentication.Features.Account.Services; +using RuntimeApps.Authentication.Features.ExternalLogin.Providers; +using RuntimeApps.Authentication.Features.ExternalLogin.Services; +using RuntimeApps.Authentication.Features.PasswordRecovery.Services; +using RuntimeApps.Authentication.Features.RefreshTokens.Services; +using RuntimeApps.Authentication.Features.Registration.Services; +using RuntimeApps.Authentication.Features.Verification.Services; +using RuntimeApps.Authentication.Identity; namespace RuntimeApps.Authentication.Test { public class VerificationPrimitivesTest { [Fact]