Skip to content

Commit 9ec75ff

Browse files
committed
duplicate interface cleanup
1 parent 120df54 commit 9ec75ff

7 files changed

Lines changed: 26 additions & 42 deletions

File tree

CodeWorks.Auth.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<Nullable>enable</Nullable>
77

88
<PackageId>CodeWorks.Auth</PackageId>
9-
<Version>0.0.4</Version>
9+
<Version>0.0.5</Version>
1010
<Authors>CodeWorks</Authors>
1111
<Company>CodeWorks</Company>
1212
<Description>Flexible, pluggable authentication module for .NET APIs with JWT, email login, and MFA support.</Description>

Interfaces/IAccountIdentityStore.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ public interface IAccountIdentityStore<TIdentity> where TIdentity : IAccountIden
99

1010
Task<TIdentity> FindByProviderAsync(string provider, string providerId);
1111

12-
12+
Task CreateAsync(TIdentity user);
13+
Task DeleteAsync(string id);
14+
15+
1316

1417
async public Task<TIdentity> MarkEmailVerifiedAsync(TIdentity user)
1518
{
@@ -25,4 +28,4 @@ async public Task<bool> IsEmailVerifiedAsync(string email)
2528
return user != null && user.IsEmailVerified;
2629
}
2730

28-
}
31+
}

Interfaces/IAuthService.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using CodeWorks.Auth.Models;
2+
3+
namespace CodeWorks.Auth.Interfaces;
4+
5+
public interface IAuthService<TIdentity> where TIdentity : IAccountIdentity
6+
{
7+
Task<AuthResult<TIdentity>> LoginAsync(string email, string password);
8+
Task<AuthResult<TIdentity>> RegisterAsync(TIdentity user, string password);
9+
Task<AuthResult<TIdentity>> ResetPasswordAsync(string email, string newPassword);
10+
Task<AuthResult<TIdentity>> RefreshAuthToken(string token, int refreshExtensionInHours = 1);
11+
AuthResult<TIdentity> GenerateAuthToken(TIdentity user);
12+
13+
}

Interfaces/IOAuthService.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,9 @@
33

44
namespace CodeWorks.Auth.Interfaces;
55

6-
public interface IOAuthService<TUser> where TUser : IAccountIdentity
6+
public interface IOAuthService<TIdentity> where TIdentity : IAccountIdentity, new()
77
{
8-
Task<AuthResult<TUser>> HandleOAuthCallbackAsync(
9-
ExternalLoginInfo loginInfo);
10-
11-
Task<string> GenerateOAuthStateAsync(string provider);
12-
8+
Task<AuthResult<TIdentity>> HandleOAuthCallbackAsync(ExternalLoginInfo loginInfo);
9+
Task<string> GenerateOAuthStateAsync(string provider, string? returnUrl = null);
1310
Task<bool> ValidateOAuthStateAsync(string state);
1411
}

Interfaces/IUserTokenStore.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ public interface IUserTokenStore
55
Task SaveTokenAsync(TokenRecord token);
66
Task<TokenRecord> GetValidTokenAsync(string token, EmailTokenPurpose purpose);
77
Task MarkTokenUsedAsync(string token);
8-
}
8+
}

Services/AuthService.cs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,6 @@
66

77
namespace CodeWorks.Auth.Services;
88

9-
public interface IAuthService<TIdentity> where TIdentity : IAccountIdentity
10-
{
11-
Task<AuthResult<TIdentity>> LoginAsync(string email, string password);
12-
Task<AuthResult<TIdentity>> RegisterAsync(TIdentity user, string password);
13-
Task<AuthResult<TIdentity>> ResetPasswordAsync(string email, string newPassword);
14-
Task<AuthResult<TIdentity>> RefreshAuthToken(string token, int refreshExtensionInHours = 1);
15-
AuthResult<TIdentity> GenerateAuthToken(TIdentity user);
16-
17-
}
18-
199
public class AuthService<TIdentity>(IAccountIdentityStore<TIdentity> store, IJwtService jwt) : IAuthService<TIdentity> where TIdentity : class, IAccountIdentity
2010
{
2111
private readonly IAccountIdentityStore<TIdentity> _store = store;

Services/OAuthService.cs

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,15 @@
66

77
namespace CodeWorks.Auth.Services;
88

9-
public interface IOAuthService<TIdentity> where TIdentity : IAccountIdentity, new()
10-
{
11-
Task<AuthResult<TIdentity>> HandleOAuthCallbackAsync(ExternalLoginInfo loginInfo);
12-
Task<string> GenerateOAuthStateAsync(string provider, string? returnUrl = null);
13-
Task<bool> ValidateOAuthStateAsync(string state);
14-
}
15-
169
public class OAuthService<TIdentity> : IOAuthService<TIdentity> where TIdentity : class, IAccountIdentity, new()
1710
{
18-
private readonly IUserStore<TIdentity> _userStore;
11+
private readonly IAccountIdentityStore<TIdentity> _userStore;
1912
private readonly IAuthService<TIdentity> _authService;
2013
private readonly IOAuthStateStore _oauthStateStore;
2114
private readonly ILogger<OAuthService<TIdentity>> _logger;
2215

2316
public OAuthService(
24-
IUserStore<TIdentity> userStore,
17+
IAccountIdentityStore<TIdentity> userStore,
2518
IAuthService<TIdentity> authService,
2619
IOAuthStateStore oauthStateStore,
2720
ILogger<OAuthService<TIdentity>> logger)
@@ -123,7 +116,7 @@ public async Task<AuthResult<TIdentity>> HandleOAuthCallbackAsync(ExternalLoginI
123116
existingUser.ProfilePictureUrl = picture;
124117
}
125118

126-
await _userStore.UpdateAsync(existingUser);
119+
await _userStore.SaveAsync(existingUser);
127120

128121
var token = _authService.GenerateAuthToken(existingUser);
129122
return AuthResult<TIdentity>.Success(existingUser, token.Token!);
@@ -177,15 +170,3 @@ public Task<bool> ValidateOAuthStateAsync(string state)
177170
});
178171
}
179172
}
180-
181-
182-
// Add to existing IUserStore interface
183-
public interface IUserStore<TUser> where TUser : IAccountIdentity
184-
{
185-
Task<TUser> FindByEmailAsync(string email);
186-
Task<TUser> FindByIdAsync(string id);
187-
Task<TUser> FindByProviderAsync(string provider, string providerId);
188-
Task CreateAsync(TUser user);
189-
Task UpdateAsync(TUser user);
190-
Task DeleteAsync(string id);
191-
}

0 commit comments

Comments
 (0)