public UsersController(
     IUserRepo userRepository,
     ITokenRepo tokenRepository,
     IMapper mapper,
     IConfiguration configuration
     )
 {
     this._userRepository  = userRepository;
     this._tokenRepository = tokenRepository;
     this._mapper          = mapper;
     _configuration        = configuration;
 }
        public AuthService(
            IDbConnectionController connectionController,
            ITransaction transaction,
            IUsersRepo usersRepo,
            ITokenRepo tokenRepo,
            ITokenMaker tokenMaker,
            IPasswordHasher passwordHasher,
            IMapper mapper)
        {
            this.connectionController = connectionController;
            this.transaction          = transaction;
            this.usersRepo            = usersRepo;
            this.tokenRepo            = tokenRepo;
            this.passwordHasher       = passwordHasher;
            this.mapper = mapper;

            this.tokenMaker = tokenMaker;
        }
        public RegistrationService(
            IDbConnectionController connectionController,
            ITransaction transaction,
            IUsersRepo usersRepo,
            ITokenRepo tokenRepo,
            INotificationSender notificationSender,
            IPasswordHasher passwordHasher,
            ITokenMaker tokenMaker,
            IMapper mapper)
        {
            this.connectionController = connectionController;
            this.transaction          = transaction;
            this.usersRepo            = usersRepo;
            this.tokenRepo            = tokenRepo;
            this.passwordHasher       = passwordHasher;
            this.tokenMaker           = tokenMaker;
            this.mapper = mapper;

            this.notificationSender = notificationSender;
        }
Exemple #4
0
        public async Task InvokeAsync(HttpContext context, IUserRepo userRepository, ITokenRepo tokenRepository)
        {
            if (await IsAnonymousAllowedAsync(context))
            {
                await _next(context);
            }
            else
            {
                try
                {
                    TokenParser      tokenParser = new TokenParser(_configuration);
                    JwtSecurityToken jwtToken    = await tokenParser.ParseTokenFromContextAsync(context);

                    int    userId       = -1;
                    string userIdString = jwtToken.Claims.First(x => x.Type == JwtRegisteredClaimNames.Sub)?.Value;
                    userId = int.Parse(userIdString);

                    User truestedUser = await userRepository.GetUserByIdAsync(userId);

                    Token trustedToken = await tokenRepository.GetTokenByUserIdAsync(userId);

                    TokenValidator tokenValidator = new TokenValidator(jwtToken, trustedToken, truestedUser);
                    if (await tokenValidator.HasValidPayloadAsync())
                    {
                        await _next(context);
                    }
                    else
                    {
                        context.Response.StatusCode = (int)HttpStatusCode.Forbidden;
                    }
                }
                catch (Exception)
                {
                    context.Response.StatusCode = (int)HttpStatusCode.Forbidden;
                }
            }
        }
Exemple #5
0
 public LoginController(IConfiguration config, IAuthRepo authRepo, ITokenRepo tokenRepo)
 {
     _config    = config;
     _authRepo  = authRepo;
     _tokenRepo = tokenRepo;
 }
Exemple #6
0
 public TokenContainer(ITokenRepo tokenRepo, INavigationService navService)
 {
     _tokenRepo  = tokenRepo;
     _navService = navService;
 }