I'm tying to use Domain Driven Design in one of my applications and have some question about user authentication.
I have an aggregate root called User which has Value Objects like UserCredentials, Password, ActivationToken, etc. I also have few domain services for managing users. For example UserRegistration service looks like this:
public interface IUserRegistrationService
{
IEnumerable<string> Register(NewUserRequest request);
}
It checks business rules that are assigned to user registration process and persist user in the database.
Now I want to authenticate user, so I've created UserAuthentication domain service:
public interface UserAuthenticationService
{
IEnumerable<string> Authenticate(AuthRequest request);
}
It takes user from the repository, checks business rules, updates and persists user data changes like LastLoginDate.
But I have some doubts if authentication process belongs to domain itself or it should belong to application service, as for my domain it doesn't matter how user is authenticated. But on the other hand authentication rules, that are checked inside this service, belong to my domain rules, so they're integral part of my domain.
So where do you put authentication in your DDD based appllications and what is your solution to this issue?