Adding authentication and authorization flow
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
|
||||
using BasicDotnetTemplate.MainProject.Models.Api.Data.Auth;
|
||||
using BasicDotnetTemplate.MainProject.Models.Api.Common.User;
|
||||
using BasicDotnetTemplate.MainProject.Core.Database;
|
||||
using BasicDotnetTemplate.MainProject.Utils;
|
||||
|
||||
namespace BasicDotnetTemplate.MainProject.Services;
|
||||
@@ -13,12 +14,16 @@ public interface IAuthService
|
||||
public class AuthService : BaseService, IAuthService
|
||||
{
|
||||
protected CryptUtils _cryptUtils;
|
||||
protected readonly IUserService _userService;
|
||||
|
||||
public AuthService(
|
||||
IConfiguration configuration
|
||||
) : base(configuration)
|
||||
IConfiguration configuration,
|
||||
SqlServerContext sqlServerContext,
|
||||
IUserService userService
|
||||
) : base(configuration, sqlServerContext)
|
||||
{
|
||||
_cryptUtils = new CryptUtils(_appSettings);
|
||||
_userService = userService;
|
||||
}
|
||||
|
||||
public async Task<AuthenticatedUser?> AuthenticateAsync(AuthenticateRequestData data)
|
||||
@@ -29,7 +34,11 @@ public class AuthService : BaseService, IAuthService
|
||||
|
||||
if (!String.IsNullOrEmpty(decryptedUsername) && !String.IsNullOrEmpty(decryptedPassword))
|
||||
{
|
||||
|
||||
var user = await this._userService.GetUserByUsernameAndPassword(decryptedUsername, decryptedPassword);
|
||||
if (user != null)
|
||||
{
|
||||
authenticatedUser = new AuthenticatedUser(user);
|
||||
}
|
||||
}
|
||||
|
||||
return authenticatedUser;
|
||||
|
||||
Reference in New Issue
Block a user